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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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
27 * ***** END GPL LICENSE BLOCK *****
34 #include "BLI_blenlib.h"
35 #include "BLI_arithb.h"
38 #include "DNA_node_types.h"
39 #include "DNA_image_types.h"
40 #include "DNA_material_types.h"
41 #include "DNA_mesh_types.h"
42 #include "DNA_action_types.h"
43 #include "DNA_color_types.h"
44 #include "DNA_customdata_types.h"
45 #include "DNA_gpencil_types.h"
46 #include "DNA_ipo_types.h"
47 #include "DNA_object_types.h"
48 #include "DNA_scene_types.h"
49 #include "DNA_space_types.h"
50 #include "DNA_screen_types.h"
51 #include "DNA_texture_types.h"
52 #include "DNA_text_types.h"
53 #include "DNA_userdef_types.h"
55 #include "BKE_context.h"
56 #include "BKE_global.h"
57 #include "BKE_image.h"
58 #include "BKE_library.h"
60 #include "BKE_material.h"
62 #include "BKE_object.h"
63 #include "BKE_texture.h"
65 #include "BKE_utildefines.h"
70 /* #include "BDR_gpencil.h" XXX */
73 #include "BIF_glutil.h"
75 #include "BIF_drawgpencil.h"
76 #include "BIF_interface.h"
77 #include "BIF_interface_icons.h"
78 #include "BIF_language.h"
79 #include "BIF_mywindow.h"
80 #include "BIF_previewrender.h"
81 #include "BIF_resources.h"
82 #include "BIF_screen.h"
83 #include "BIF_space.h"
87 #include "BSE_drawipo.h"
95 #include "MEM_guardedalloc.h"
97 #include "ED_space_api.h"
98 #include "ED_screen.h"
101 #include "RNA_access.h"
102 #include "RNA_define.h"
105 #include "WM_types.h"
107 #include "UI_view2d.h"
109 #include "UI_interface.h"
110 #include "UI_resources.h"
112 #include "RE_pipeline.h"
113 #include "IMB_imbuf_types.h"
115 /*#include "blendef.h"
116 #include "butspace.h"*/
117 /*#include "interface.h"*/ /* urm... for rasterpos_safe, roundbox */
118 /*#include "mydevice.h"*/
120 #include "node_intern.h"
122 extern void autocomplete_uv(char *str, void *arg_v);
123 // XXX extern int verify_valid_uv_name(char *str);
125 /* autocomplete callback for buttons */
126 static void autocomplete_vcol(bContext *C, char *str, void *arg_v)
129 CustomDataLayer *layer;
130 AutoComplete *autocpl;
136 autocpl= autocomplete_begin(str, 32);
138 /* search if str matches the beginning of name */
139 for(me= G.main->mesh.first; me; me=me->id.next)
140 for(a=0, layer= me->fdata.layers; a<me->fdata.totlayer; a++, layer++)
141 if(layer->type == CD_MCOL)
142 autocomplete_do_name(autocpl, layer->name);
144 autocomplete_end(autocpl, str);
147 static int verify_valid_vcol_name(char *str)
150 CustomDataLayer *layer;
156 /* search if str matches the name */
157 for(me= G.main->mesh.first; me; me=me->id.next)
158 for(a=0, layer= me->fdata.layers; a<me->fdata.totlayer; a++, layer++)
159 if(layer->type == CD_MCOL)
160 if(strcmp(layer->name, str)==0)
166 /* ****************** GENERAL CALLBACKS FOR NODES ***************** */
168 static void node_ID_title_cb(bContext *C, void *node_v, void *unused_v)
173 test_idbutton(node->id->name+2); /* library.c, verifies unique name */
174 BLI_strncpy(node->name, node->id->name+2, 21);
179 static void node_but_title_cb(bContext *C, void *node_v, void *but_v)
181 // bNode *node= node_v;
182 // XXX uiBut *bt= but_v;
183 // XXX BLI_strncpy(node->name, bt->drawstr, NODE_MAXSTR);
185 // allqueue(REDRAWNODE, 0);
188 static void node_group_alone_cb(bContext *C, void *node_v, void *unused_v)
194 // allqueue(REDRAWNODE, 0);
197 /* ****************** BUTTON CALLBACKS FOR ALL TREES ***************** */
199 static int node_buts_group(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
201 if(block && node->id) {
205 uiBlockBeginAlign(block);
208 width= (short)(butr->xmax-butr->xmin - (node->id->us>1?19.0f:0.0f));
209 bt= uiDefBut(block, TEX, B_NOP, "NT:",
210 (short)butr->xmin, (short)butr->ymin, width, 19,
211 node->id->name+2, 0.0, 19.0, 0, 0, "NodeTree name");
212 uiButSetFunc(bt, node_ID_title_cb, node, NULL);
217 sprintf(str1, "%d", node->id->us);
218 bt= uiDefBut(block, BUT, B_NOP, str1,
219 (short)butr->xmax-19, (short)butr->ymin, 19, 19,
220 NULL, 0, 0, 0, 0, "Displays number of users.");
221 uiButSetFunc(bt, node_group_alone_cb, node, NULL);
224 uiBlockEndAlign(block);
229 static int node_buts_value(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
232 bNodeSocket *sock= node->outputs.first; /* first socket stores value */
234 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "",
235 (short)butr->xmin, (short)butr->ymin, butr->xmax-butr->xmin, 20,
236 sock->ns.vec, sock->ns.min, sock->ns.max, 10, 2, "");
242 static int node_buts_rgb(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
245 bNodeSocket *sock= node->outputs.first; /* first socket stores value */
247 /* enforce square box drawing */
248 uiBlockSetEmboss(block, UI_EMBOSSP);
250 uiDefButF(block, HSVCUBE, B_NODE_EXEC+node->nr, "",
251 (short)butr->xmin, (short)butr->ymin, butr->xmax-butr->xmin, 12,
252 sock->ns.vec, 0.0f, 1.0f, 3, 0, "");
253 uiDefButF(block, HSVCUBE, B_NODE_EXEC+node->nr, "",
254 (short)butr->xmin, (short)butr->ymin+15, butr->xmax-butr->xmin, butr->ymax-butr->ymin -15 -15,
255 sock->ns.vec, 0.0f, 1.0f, 2, 0, "");
256 uiDefButF(block, COL, B_NOP, "",
257 (short)butr->xmin, (short)butr->ymax-12, butr->xmax-butr->xmin, 12,
258 sock->ns.vec, 0.0, 0.0, -1, 0, "");
259 /* the -1 above prevents col button to popup a color picker */
261 uiBlockSetEmboss(block, UI_EMBOSS);
264 return 30 + (int)(node->width-NODE_DY);
267 static int node_buts_mix_rgb(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
271 int a_but= (ntree->type==NTREE_COMPOSIT);
274 uiBlockBeginAlign(block);
275 bt=uiDefButS(block, MENU, B_NODE_EXEC+node->nr, "Mix %x0|Add %x1|Subtract %x3|Multiply %x2|Screen %x4|Overlay %x9|Divide %x5|Difference %x6|Darken %x7|Lighten %x8|Dodge %x10|Burn %x11|Color %x15|Value %x14|Saturation %x13|Hue %x12",
276 (short)butr->xmin, (short)butr->ymin, butr->xmax-butr->xmin -(a_but?20:0), 20,
277 &node->custom1, 0, 0, 0, 0, "");
278 uiButSetFunc(bt, node_but_title_cb, node, bt);
279 /* Alpha option, composite */
281 uiDefButS(block, TOG, B_NODE_EXEC+node->nr, "A",
282 (short)butr->xmax-20, (short)butr->ymin, 20, 20,
283 &node->custom2, 0, 0, 0, 0, "Include Alpha of 2nd input in this operation");
288 static int node_buts_time(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
291 CurveMapping *cumap= node->storage;
292 short dx= (short)((butr->xmax-butr->xmin)/2);
295 // XXX curvemap_buttons(block, node->storage, 's', B_NODE_EXEC+node->nr, B_REDR, butr);
298 cumap->flag |= CUMA_DRAW_CFRA;
299 if(node->custom1<node->custom2)
300 ;// XXX cumap->sample[0]= (float)(CFRA - node->custom1)/(float)(node->custom2-node->custom1);
303 uiBlockBeginAlign(block);
304 uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "Sta:",
305 (short)butr->xmin, (short)butr->ymin-22, dx, 19,
306 &node->custom1, 1.0, 20000.0, 0, 0, "Start frame");
307 uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "End:",
308 (short)butr->xmin+dx, (short)butr->ymin-22, dx, 19,
309 &node->custom2, 1.0, 20000.0, 0, 0, "End frame");
312 return node->width-NODE_DY;
315 static int node_buts_valtorgb(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
319 ; // XXX draw_colorband_buts_small(block, node->storage, butr, B_NODE_EXEC+node->nr);
325 static int node_buts_curvevec(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
328 ; // XXX curvemap_buttons(block, node->storage, 'v', B_NODE_EXEC+node->nr, B_REDR, butr);
330 return (int)(node->width-NODE_DY);
333 static float *_sample_col= NULL; // bad bad, 2.5 will do better?
334 void node_curvemap_sample(float *col)
339 static int node_buts_curvecol(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
342 CurveMapping *cumap= node->storage;
344 cumap->flag |= CUMA_DRAW_SAMPLE;
345 VECCOPY(cumap->sample, _sample_col);
348 cumap->flag &= ~CUMA_DRAW_SAMPLE;
350 // XXX curvemap_buttons(block, node->storage, 'c', B_NODE_EXEC+node->nr, B_REDR, butr);
352 return (int)(node->width-NODE_DY);
355 static int node_buts_normal(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
358 bNodeSocket *sock= node->outputs.first; /* first socket stores normal */
360 uiDefButF(block, BUT_NORMAL, B_NODE_EXEC+node->nr, "",
361 (short)butr->xmin, (short)butr->ymin, butr->xmax-butr->xmin, butr->ymax-butr->ymin,
362 sock->ns.vec, 0.0f, 1.0f, 0, 0, "");
365 return (int)(node->width-NODE_DY);
368 static void node_browse_tex_cb(bContext *C, void *ntree_v, void *node_v)
370 bNodeTree *ntree= ntree_v;
374 if(node->menunr<1) return;
380 tex= BLI_findlink(&G.main->tex, node->menunr-1);
383 id_us_plus(node->id);
384 BLI_strncpy(node->name, node->id->name+2, 21);
386 nodeSetActive(ntree, node);
388 if( ntree->type == NTREE_TEXTURE )
389 ntreeTexCheckCyclics( ntree );
391 // allqueue(REDRAWBUTSSHADING, 0);
392 // allqueue(REDRAWNODE, 0);
393 NodeTagChanged(ntree, node);
398 static void node_dynamic_update_cb(bContext *C, void *ntree_v, void *node_v)
401 bNode *node= (bNode *)node_v;
405 if (BTST(node->custom1, NODE_DYNAMIC_ERROR)) error= 1;
407 /* Users only have to press the "update" button in one pynode
408 * and we also update all others sharing the same script */
409 for (ma= G.main->mat.first; ma; ma= ma->id.next) {
412 for (nd= ma->nodetree->nodes.first; nd; nd= nd->next) {
413 if ((nd->type == NODE_DYNAMIC) && (nd->id == id)) {
415 nd->custom1= BSET(nd->custom1, NODE_DYNAMIC_REPARSE);
418 nd->custom1= BSET(nd->custom1, NODE_DYNAMIC_ERROR);
424 // allqueue(REDRAWBUTSSHADING, 0);
425 // allqueue(REDRAWNODE, 0);
426 // XXX BIF_preview_changed(ID_MA);
429 static int node_buts_texture(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
433 ((Tex*)node->id)->use_nodes &&
434 (node->type != CMP_NODE_TEXTURE) &&
435 (node->type != TEX_NODE_TEXTURE)
441 short width = (short)(butr->xmax - butr->xmin);
443 /* browse button texture */
444 uiBlockBeginAlign(block);
445 IDnames_to_pupstring(&strp, NULL, "", &(G.main->tex), NULL, NULL);
447 bt= uiDefButS(block, MENU, B_NODE_EXEC+node->nr, strp,
448 butr->xmin, butr->ymin+(multi?30:0), 20, 19,
449 &node->menunr, 0, 0, 0, 0, "Browse texture");
450 uiButSetFunc(bt, node_browse_tex_cb, ntree, node);
451 if(strp) MEM_freeN(strp);
454 bt= uiDefBut(block, TEX, B_NOP, "TE:",
455 butr->xmin+19, butr->ymin+(multi?30:0), butr->xmax-butr->xmin-19, 19,
456 node->id->name+2, 0.0, 19.0, 0, 0, "Texture name");
457 uiButSetFunc(bt, node_ID_title_cb, node, NULL);
459 uiBlockEndAlign(block);
462 char *menustr = ntreeTexOutputMenu(((Tex*)node->id)->nodetree);
463 uiDefButS(block, MENU, B_MATPRV, menustr, butr->xmin, butr->ymin, width, 19, &node->custom1, 0, 0, 0, 0, "Which output to use, for multi-output textures");
469 else return multi? 50: 20;
472 static int node_buts_math(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
477 bt=uiDefButS(block, MENU, B_NODE_EXEC, "Add %x0|Subtract %x1|Multiply %x2|Divide %x3|Sine %x4|Cosine %x5|Tangent %x6|Arcsine %x7|Arccosine %x8|Arctangent %x9|Power %x10|Logarithm %x11|Minimum %x12|Maximum %x13|Round %x14|Less Than %x15|Greater Than %x16", butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20, &node->custom1, 0, 0, 0, 0, "");
478 uiButSetFunc(bt, node_but_title_cb, node, bt);
484 /* ****************** BUTTON CALLBACKS FOR SHADER NODES ***************** */
486 static void node_browse_text_cb(bContext *C, void *ntree_v, void *node_v)
488 bNodeTree *ntree= ntree_v;
492 if(node->menunr<1) return;
498 node->id= BLI_findlink(&G.main->text, node->menunr-1);
499 id_us_plus(node->id);
500 BLI_strncpy(node->name, node->id->name+2, 21); /* huh? why 21? */
502 node->custom1= BSET(node->custom1, NODE_DYNAMIC_NEW);
504 nodeSetActive(ntree, node);
506 // allqueue(REDRAWBUTSSHADING, 0);
507 // allqueue(REDRAWNODE, 0);
512 static void node_mat_alone_cb(bContext *C, void *node_v, void *unused)
516 node->id= (ID *)copy_material((Material *)node->id);
518 //BIF_undo_push("Single user material");
519 // allqueue(REDRAWBUTSSHADING, 0);
520 // allqueue(REDRAWNODE, 0);
521 // allqueue(REDRAWOOPS, 0);
524 static void node_browse_mat_cb(bContext *C, void *ntree_v, void *node_v)
526 bNodeTree *ntree= ntree_v;
529 if(node->menunr<1) return;
531 if(node->menunr==32767) { /* code for Add New */
533 /* make copy, but make sure it doesnt have the node tag nor nodes */
534 Material *ma= (Material *)node->id;
536 ma= copy_material(ma);
539 ntreeFreeTree(ma->nodetree);
540 MEM_freeN(ma->nodetree);
545 else node->id= (ID *)add_material("MatNode");
548 if(node->id) node->id->us--;
549 node->id= BLI_findlink(&G.main->mat, node->menunr-1);
550 id_us_plus(node->id);
552 BLI_strncpy(node->name, node->id->name+2, 21);
554 nodeSetActive(ntree, node);
556 // allqueue(REDRAWBUTSSHADING, 0);
557 // allqueue(REDRAWNODE, 0);
558 // XXX BIF_preview_changed(ID_MA);
563 static void node_new_mat_cb(bContext *C, void *ntree_v, void *node_v)
565 bNodeTree *ntree= ntree_v;
568 node->id= (ID *)add_material("MatNode");
569 BLI_strncpy(node->name, node->id->name+2, 21);
571 nodeSetActive(ntree, node);
573 // allqueue(REDRAWBUTSSHADING, 0);
574 // allqueue(REDRAWNODE, 0);
575 // XXX BIF_preview_changed(ID_MA);
579 static void node_texmap_cb(bContext *C, void *texmap_v, void *unused_v)
581 init_mapping(texmap_v);
584 static int node_shader_buts_material(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
588 short dx= (short)((butr->xmax-butr->xmin)/3.0f), has_us= (node->id && node->id->us>1);
589 short dy= (short)butr->ymin;
592 /* WATCH IT: we use this callback in material buttons, but then only want first row */
593 if(butr->ymax-butr->ymin > 21.0f) dy+= 19;
595 uiBlockBeginAlign(block);
596 if(node->id==NULL) uiBlockSetCol(block, TH_REDALERT);
597 else if(has_us) uiBlockSetCol(block, TH_BUT_SETTING1);
598 else uiBlockSetCol(block, TH_BUT_SETTING2);
601 IDnames_to_pupstring(&strp, NULL, "ADD NEW %x32767", &(G.main->mat), NULL, NULL);
603 bt= uiDefButS(block, MENU, B_NOP, strp,
604 butr->xmin, dy, 19, 19,
605 &node->menunr, 0, 0, 0, 0, "Browses existing choices or adds NEW");
606 uiButSetFunc(bt, node_browse_mat_cb, ntree, node);
607 if(strp) MEM_freeN(strp);
611 bt= uiDefBut(block, BUT, B_NOP, "Add New",
612 butr->xmin+19, dy, (short)(butr->xmax-butr->xmin-19.0f), 19,
613 NULL, 0.0, 0.0, 0, 0, "Add new Material");
614 uiButSetFunc(bt, node_new_mat_cb, ntree, node);
615 uiBlockSetCol(block, TH_AUTO);
619 short width= (short)(butr->xmax-butr->xmin-19.0f - (has_us?19.0f:0.0f));
620 bt= uiDefBut(block, TEX, B_NOP, "MA:",
621 butr->xmin+19, dy, width, 19,
622 node->id->name+2, 0.0, 19.0, 0, 0, "Material name");
623 uiButSetFunc(bt, node_ID_title_cb, node, NULL);
628 sprintf(str1, "%d", node->id->us);
629 bt= uiDefBut(block, BUT, B_NOP, str1,
630 butr->xmax-19, dy, 19, 19,
631 NULL, 0, 0, 0, 0, "Displays number of users. Click to make a single-user copy.");
632 uiButSetFunc(bt, node_mat_alone_cb, node, NULL);
635 /* WATCH IT: we use this callback in material buttons, but then only want first row */
636 if(butr->ymax-butr->ymin > 21.0f) {
638 uiBlockSetCol(block, TH_AUTO);
639 uiDefButBitS(block, TOG, SH_NODE_MAT_DIFF, B_NODE_EXEC+node->nr, "Diff",
640 butr->xmin, butr->ymin, dx, 19,
641 &node->custom1, 0, 0, 0, 0, "Material Node outputs Diffuse");
642 uiDefButBitS(block, TOG, SH_NODE_MAT_SPEC, B_NODE_EXEC+node->nr, "Spec",
643 butr->xmin+dx, butr->ymin, dx, 19,
644 &node->custom1, 0, 0, 0, 0, "Material Node outputs Specular");
645 uiDefButBitS(block, TOG, SH_NODE_MAT_NEG, B_NODE_EXEC+node->nr, "Neg Normal",
646 butr->xmax-dx, butr->ymin, dx, 19,
647 &node->custom1, 0, 0, 0, 0, "Material Node uses inverted Normal");
650 uiBlockEndAlign(block);
655 static int node_shader_buts_mapping(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
658 TexMapping *texmap= node->storage;
659 short dx= (short)((butr->xmax-butr->xmin)/7.0f);
660 short dy= (short)(butr->ymax-19);
662 uiBlockSetFunc(block, node_texmap_cb, texmap, NULL); /* all buttons get this */
664 uiBlockBeginAlign(block);
665 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "", butr->xmin+dx, dy, 2*dx, 19, texmap->loc, -1000.0f, 1000.0f, 10, 2, "");
666 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->loc+1, -1000.0f, 1000.0f, 10, 2, "");
667 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->loc+2, -1000.0f, 1000.0f, 10, 2, "");
669 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "", butr->xmin+dx, dy, 2*dx, 19, texmap->rot, -1000.0f, 1000.0f, 1000, 1, "");
670 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->rot+1, -1000.0f, 1000.0f, 1000, 1, "");
671 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->rot+2, -1000.0f, 1000.0f, 1000, 1, "");
673 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "", butr->xmin+dx, dy, 2*dx, 19, texmap->size, -1000.0f, 1000.0f, 10, 2, "");
674 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->size+1, -1000.0f, 1000.0f, 10, 2, "");
675 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->size+2, -1000.0f, 1000.0f, 10, 2, "");
677 uiBlockBeginAlign(block);
678 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "", butr->xmin+dx, dy, 2*dx, 19, texmap->min, -10.0f, 10.0f, 100, 2, "");
679 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->min+1, -10.0f, 10.0f, 100, 2, "");
680 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->min+2, -10.0f, 10.0f, 100, 2, "");
682 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "", butr->xmin+dx, dy, 2*dx, 19, texmap->max, -10.0f, 10.0f, 10, 2, "");
683 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->max+1, -10.0f, 10.0f, 10, 2, "");
684 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->max+2, -10.0f, 10.0f, 10, 2, "");
685 uiBlockEndAlign(block);
689 dy= (short)(butr->ymax-19);
690 uiDefBut(block, LABEL, B_NOP, "Loc", butr->xmin, dy, dx, 19, NULL, 0.0f, 0.0f, 0, 0, "");
692 uiDefBut(block, LABEL, B_NOP, "Rot", butr->xmin, dy, dx, 19, NULL, 0.0f, 0.0f, 0, 0, "");
694 uiDefBut(block, LABEL, B_NOP, "Size", butr->xmin, dy, dx, 19, NULL, 0.0f, 0.0f, 0, 0, "");
696 uiDefButBitI(block, TOG, TEXMAP_CLIP_MIN, B_NODE_EXEC+node->nr, "Min", butr->xmin, dy, dx-4, 19, &texmap->flag, 0.0f, 0.0f, 0, 0, "");
698 uiDefButBitI(block, TOG, TEXMAP_CLIP_MAX, B_NODE_EXEC+node->nr, "Max", butr->xmin, dy, dx-4, 19, &texmap->flag, 0.0f, 0.0f, 0, 0, "");
704 static int node_shader_buts_vect_math(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
709 bt=uiDefButS(block, MENU, B_NODE_EXEC, "Add %x0|Subtract %x1|Average %x2|Dot Product %x3 |Cross Product %x4|Normalize %x5", butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20, &node->custom1, 0, 0, 0, 0, "");
710 uiButSetFunc(bt, node_but_title_cb, node, bt);
715 static int node_shader_buts_geometry(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
719 NodeGeometry *ngeo= (NodeGeometry*)node->storage;
721 // XXX if(!verify_valid_uv_name(ngeo->uvname))
722 // XXX uiBlockSetCol(block, TH_REDALERT);
723 but= uiDefBut(block, TEX, B_NODE_EXEC+node->nr, "UV:", butr->xmin, butr->ymin+20, butr->xmax-butr->xmin, 20, ngeo->uvname, 0, 31, 0, 0, "Set name of UV layer to use, default is active UV layer");
724 // uiButSetCompleteFunc(but, autocomplete_uv, NULL);
725 uiBlockSetCol(block, TH_AUTO);
727 if(!verify_valid_vcol_name(ngeo->colname))
728 uiBlockSetCol(block, TH_REDALERT);
729 but= uiDefBut(block, TEX, B_NODE_EXEC+node->nr, "Col:", butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20, ngeo->colname, 0, 31, 0, 0, "Set name of vertex color layer to use, default is active vertex color layer");
730 uiButSetCompleteFunc(but, autocomplete_vcol, NULL);
731 uiBlockSetCol(block, TH_AUTO);
737 static int node_shader_buts_dynamic(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
741 // XXX SpaceNode *snode= curarea->spacedata.first;
742 short dy= (short)butr->ymin;
745 /* B_NODE_EXEC is handled in butspace.c do_node_buts */
748 IDnames_to_pupstring(&strp, NULL, "", &(G.main->text), NULL, NULL);
750 bt= uiDefButS(block, MENU, B_NODE_EXEC/*+node->nr*/, strp,
751 butr->xmin, dy, 19, 19,
752 &node->menunr, 0, 0, 0, 0, "Browses existing choices");
753 uiButSetFunc(bt, node_browse_text_cb, ntree, node);
755 if(strp) MEM_freeN(strp);
758 bt = uiDefBut(block, BUT, B_NOP, "Update",
759 butr->xmin+xoff, butr->ymin+20, 50, 19,
760 &node->menunr, 0.0, 19.0, 0, 0, "Refresh this node (and all others that use the same script)");
761 uiButSetFunc(bt, node_dynamic_update_cb, ntree, node);
763 if (BTST(node->custom1, NODE_DYNAMIC_ERROR)) {
764 // UI_ThemeColor(TH_REDALERT);
765 // XXX ui_rasterpos_safe(butr->xmin + xoff, butr->ymin + 5, snode->aspect);
766 // XXX snode_drawstring(snode, "Error! Check console...", butr->xmax - butr->xmin);
774 /* only once called */
775 static void node_shader_set_butfunc(bNodeType *ntype)
777 switch(ntype->type) {
778 /* case NODE_GROUP: note, typeinfo for group is generated... see "XXX ugly hack" */
780 case SH_NODE_MATERIAL:
781 case SH_NODE_MATERIAL_EXT:
782 ntype->butfunc= node_shader_buts_material;
784 case SH_NODE_TEXTURE:
785 ntype->butfunc= node_buts_texture;
788 ntype->butfunc= node_buts_normal;
790 case SH_NODE_CURVE_VEC:
791 ntype->butfunc= node_buts_curvevec;
793 case SH_NODE_CURVE_RGB:
794 ntype->butfunc= node_buts_curvecol;
796 case SH_NODE_MAPPING:
797 ntype->butfunc= node_shader_buts_mapping;
800 ntype->butfunc= node_buts_value;
803 ntype->butfunc= node_buts_rgb;
805 case SH_NODE_MIX_RGB:
806 ntype->butfunc= node_buts_mix_rgb;
808 case SH_NODE_VALTORGB:
809 ntype->butfunc= node_buts_valtorgb;
812 ntype->butfunc= node_buts_math;
814 case SH_NODE_VECT_MATH:
815 ntype->butfunc= node_shader_buts_vect_math;
817 case SH_NODE_GEOMETRY:
818 ntype->butfunc= node_shader_buts_geometry;
821 ntype->butfunc= node_shader_buts_dynamic;
824 ntype->butfunc= NULL;
828 /* ****************** BUTTON CALLBACKS FOR COMPOSITE NODES ***************** */
832 static void node_browse_image_cb(bContext *C, void *ntree_v, void *node_v)
834 bNodeTree *ntree= ntree_v;
837 nodeSetActive(ntree, node);
839 if(node->menunr<1) return;
840 if(node->menunr==32767) { /* code for Load New */
841 /// addqueue(curarea->win, UI_BUT_EVENT, B_NODE_LOADIMAGE); XXX
844 if(node->id) node->id->us--;
845 node->id= BLI_findlink(&G.main->image, node->menunr-1);
846 id_us_plus(node->id);
848 BLI_strncpy(node->name, node->id->name+2, 21);
850 NodeTagChanged(ntree, node);
851 BKE_image_signal((Image *)node->id, node->storage, IMA_SIGNAL_USER_NEW_IMAGE);
852 // addqueue(curarea->win, UI_BUT_EVENT, B_NODE_EXEC+node->nr); XXX
857 static void node_active_cb(bContext *C, void *ntree_v, void *node_v)
859 nodeSetActive(ntree_v, node_v);
861 static void node_image_type_cb(bContext *C, void *node_v, void *unused)
864 // allqueue(REDRAWNODE, 1);
867 static char *node_image_type_pup(void)
869 char *str= MEM_mallocN(256, "image type pup");
874 a= sprintf(str, "Image Type %%t|");
875 a+= sprintf(str+a, " Image %%x%d %%i%d|", IMA_SRC_FILE, ICON_IMAGE_DEHLT);
876 a+= sprintf(str+a, " Movie %%x%d %%i%d|", IMA_SRC_MOVIE, ICON_SEQUENCE);
877 a+= sprintf(str+a, " Sequence %%x%d %%i%d|", IMA_SRC_SEQUENCE, ICON_IMAGE_COL);
878 a+= sprintf(str+a, " Generated %%x%d %%i%d", IMA_SRC_GENERATED, ICON_BLANK1);
883 /* copy from buttons_shading.c */
884 static char *layer_menu(RenderResult *rr)
887 int len= 40 + 40*BLI_countlist(&rr->layers);
889 char *str= MEM_callocN(len, "menu layers");
891 strcpy(str, "Layer %t");
893 for(nr=0, rl= rr->layers.first; rl; rl= rl->next, nr++) {
894 a+= sprintf(str+a, "|%s %%x%d", rl->name, nr);
900 static void image_layer_cb(bContext *C, void *ima_v, void *iuser_v)
902 Scene *scene= CTX_data_scene(C);
904 ntreeCompositForceHidden(scene->nodetree, scene);
905 BKE_image_multilayer_index(ima_v, iuser_v);
906 // allqueue(REDRAWNODE, 0);
909 static int node_composit_buts_image(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
911 ImageUser *iuser= node->storage;
915 short dy= (short)butr->ymax-19;
918 uiBlockBeginAlign(block);
919 uiBlockSetCol(block, TH_BUT_SETTING2);
922 IMAnames_to_pupstring(&strp, NULL, "LOAD NEW %x32767", &(G.main->image), NULL, NULL);
924 bt= uiDefButS(block, MENU, B_NOP, strp,
925 butr->xmin, dy, 19, 19,
926 &node->menunr, 0, 0, 0, 0, "Browses existing choices");
927 uiButSetFunc(bt, node_browse_image_cb, ntree, node);
928 if(strp) MEM_freeN(strp);
932 bt= uiDefBut(block, BUT, B_NODE_LOADIMAGE, "Load New",
933 butr->xmin+19, dy, (short)(butr->xmax-butr->xmin-19.0f), 19,
934 NULL, 0.0, 0.0, 0, 0, "Add new Image");
935 uiButSetFunc(bt, node_active_cb, ntree, node);
936 uiBlockSetCol(block, TH_AUTO);
939 /* name button + type */
940 Image *ima= (Image *)node->id;
941 short xmin= (short)butr->xmin, xmax= (short)butr->xmax;
942 short width= xmax - xmin - 45;
943 short icon= ICON_IMAGE_DEHLT;
945 if(ima->source==IMA_SRC_MOVIE) icon= ICON_SEQUENCE;
946 else if(ima->source==IMA_SRC_SEQUENCE) icon= ICON_IMAGE_COL;
947 else if(ima->source==IMA_SRC_GENERATED) icon= ICON_BLANK1;
949 bt= uiDefBut(block, TEX, B_NOP, "IM:",
950 xmin+19, dy, width, 19,
951 node->id->name+2, 0.0, 19.0, 0, 0, "Image name");
952 uiButSetFunc(bt, node_ID_title_cb, node, NULL);
954 /* buffer type option */
955 strp= node_image_type_pup();
956 bt= uiDefIconTextButS(block, MENU, B_NOP, icon, strp,
958 &ima->source, 0.0, 19.0, 0, 0, "Image type");
959 uiButSetFunc(bt, node_image_type_cb, node, ima);
962 if( ELEM(ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE) ) {
963 width= (xmax-xmin)/2;
966 uiDefButI(block, NUM, B_NODE_EXEC+node->nr, "Frs:",
968 &iuser->frames, 1.0, MAXFRAMEF, 0, 0, "Amount of images used in animation");
969 uiDefButI(block, NUM, B_NODE_EXEC+node->nr, "SFra:",
970 xmin+width, dy, width, 19,
971 &iuser->sfra, 1.0, MAXFRAMEF, 0, 0, "Start frame of animation");
973 uiDefButI(block, NUM, B_NODE_EXEC+node->nr, "Offs:",
975 &iuser->offset, -MAXFRAMEF, MAXFRAMEF, 0, 0, "Offsets the number of the frame to use in the animation");
976 uiDefButS(block, TOG, B_NODE_EXEC+node->nr, "Cycl",
977 xmin+width, dy, width-20, 19,
978 &iuser->cycl, 0.0, 0.0, 0, 0, "Make animation go cyclic");
979 uiDefIconButBitS(block, TOG, IMA_ANIM_ALWAYS, B_NODE_EXEC+node->nr, ICON_AUTO,
981 &iuser->flag, 0.0, 0.0, 0, 0, "Always refresh Image on frame changes");
983 if( ima->type==IMA_TYPE_MULTILAYER && ima->rr) {
984 RenderLayer *rl= BLI_findlink(&ima->rr->layers, iuser->layer);
988 strp= layer_menu(ima->rr);
989 bt= uiDefButS(block, MENU, B_NODE_EXEC+node->nr, strp,
991 &iuser->layer, 0.0, 10000.0, 0, 0, "Layer");
992 uiButSetFunc(bt, image_layer_cb, ima->rr, node->storage);
1000 Image *ima= (Image *)node->id;
1003 /* for each draw we test for anim refresh event */
1004 if(iuser->flag & IMA_ANIM_REFRESHED) {
1005 iuser->flag &= ~IMA_ANIM_REFRESHED;
1006 // addqueue(curarea->win, UI_BUT_EVENT, B_NODE_EXEC+node->nr); XXX
1009 if( ELEM(ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE) )
1011 if( ima->type==IMA_TYPE_MULTILAYER)
1019 /* if we use render layers from other scene, we make a nice title */
1020 static void set_render_layers_title(bContext *C, void *node_v, void *unused)
1022 bNode *node= node_v;
1024 SceneRenderLayer *srl;
1028 BLI_strncpy(str, node->id->name+2, 21);
1030 sce= (Scene *)node->id;
1034 sce= CTX_data_scene(C);
1036 srl= BLI_findlink(&sce->r.layers, node->custom1);
1039 srl= sce->r.layers.first;
1042 strcat(str, srl->name);
1043 BLI_strncpy(node->name, str, 32);
1046 static char *scene_layer_menu(Scene *sce)
1048 SceneRenderLayer *srl;
1049 int len= 40 + 40*BLI_countlist(&sce->r.layers);
1051 char *str= MEM_callocN(len, "menu layers");
1053 strcpy(str, "Active Layer %t");
1055 for(nr=0, srl= sce->r.layers.first; srl; srl= srl->next, nr++) {
1056 a+= sprintf(str+a, "|%s %%x%d", srl->name, nr);
1062 static void node_browse_scene_cb(bContext *C, void *ntree_v, void *node_v)
1064 bNodeTree *ntree= ntree_v;
1065 bNode *node= node_v;
1068 if(node->menunr<1) return;
1074 sce= BLI_findlink(&G.main->scene, node->menunr-1);
1075 if(sce!=CTX_data_scene(C)) {
1077 id_us_plus(node->id);
1080 set_render_layers_title(C, node, NULL);
1081 nodeSetActive(ntree, node);
1083 // allqueue(REDRAWBUTSSHADING, 0);
1084 // allqueue(REDRAWNODE, 0);
1085 NodeTagChanged(ntree, node);
1091 static int node_composit_buts_renderlayers(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1094 Scene *scene= NULL; // XXX CTX_data_scene(C) can't work here. node->id has to be set default (ton)
1098 /* browse button scene */
1099 uiBlockBeginAlign(block);
1100 IDnames_to_pupstring(&strp, NULL, "", &(G.main->scene), NULL, NULL);
1102 bt= uiDefButS(block, MENU, B_NOP, strp,
1103 butr->xmin, butr->ymin, 20, 19,
1104 &node->menunr, 0, 0, 0, 0, "Browse Scene to use RenderLayer from");
1105 uiButSetFunc(bt, node_browse_scene_cb, ntree, node);
1106 if(strp) MEM_freeN(strp);
1108 /* browse button layer */
1109 strp= scene_layer_menu(node->id?(Scene *)node->id:scene);
1111 bt= uiDefIconTextButS(block, MENU, B_NODE_EXEC+node->nr, ICON_SCENE_DEHLT, strp,
1112 butr->xmin+20, butr->ymin, (butr->xmax-butr->xmin)-40, 19,
1113 &node->custom1, 0, 0, 0, 0, "Choose Render Layer");
1115 bt= uiDefButS(block, MENU, B_NODE_EXEC+node->nr, strp,
1116 butr->xmin+20, butr->ymin, (butr->xmax-butr->xmin)-40, 19,
1117 &node->custom1, 0, 0, 0, 0, "Choose Render Layer");
1118 uiButSetFunc(bt, set_render_layers_title, node, NULL);
1122 /* uses custom2, not the best implementation of the world... but we need it to work now :) */
1123 bt= uiDefIconButS(block, TOG, B_NODE_EXEC+node->nr, ICON_SCENE,
1124 butr->xmax-20, butr->ymin, 20, 19,
1125 &node->custom2, 0, 0, 0, 0, "Re-render this Layer");
1131 static void node_blur_relative_cb(bContext *C, void *node, void *poin2)
1134 NodeBlurData *nbd= nodev->storage;
1135 if(nbd->image_in_width != 0){
1136 if(nbd->relative){ /* convert absolute values to relative */
1137 nbd->percentx= (float)(nbd->sizex)/nbd->image_in_width;
1138 nbd->percenty= (float)(nbd->sizey)/nbd->image_in_height;
1139 }else{ /* convert relative values to absolute */
1140 nbd->sizex= (int)(nbd->percentx*nbd->image_in_width);
1141 nbd->sizey= (int)(nbd->percenty*nbd->image_in_height);
1144 // allqueue(REDRAWNODE, 0);
1146 static void node_blur_update_sizex_cb(bContext *C, void *node, void *poin2)
1149 NodeBlurData *nbd= nodev->storage;
1151 nbd->sizex= (int)(nbd->percentx*nbd->image_in_width);
1153 static void node_blur_update_sizey_cb(bContext *C, void *node, void *poin2)
1156 NodeBlurData *nbd= nodev->storage;
1158 nbd->sizey= (int)(nbd->percenty*nbd->image_in_height);
1160 static int node_composit_buts_blur(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1163 NodeBlurData *nbd= node->storage;
1165 short dy= butr->ymin+58;
1166 short dx= (butr->xmax-butr->xmin)/2;
1169 uiBlockBeginAlign(block);
1170 sprintf(str, "Filter Type%%t|Flat %%x%d|Tent %%x%d|Quad %%x%d|Cubic %%x%d|Gauss %%x%d|Fast Gauss%%x%d|CatRom %%x%d|Mitch %%x%d", R_FILTER_BOX, R_FILTER_TENT, R_FILTER_QUAD, R_FILTER_CUBIC, R_FILTER_GAUSS, R_FILTER_FAST_GAUSS, R_FILTER_CATROM, R_FILTER_MITCH);
1171 uiDefButS(block, MENU, B_NODE_EXEC+node->nr,str,
1172 butr->xmin, dy, dx*2, 19,
1173 &nbd->filtertype, 0, 0, 0, 0, "Set sampling filter for blur");
1175 if (nbd->filtertype != R_FILTER_FAST_GAUSS) {
1176 uiDefButC(block, TOG, B_NODE_EXEC+node->nr, "Bokeh",
1177 butr->xmin, dy, dx, 19,
1178 &nbd->bokeh, 0, 0, 0, 0, "Uses circular filter, warning it's slow!");
1179 uiDefButC(block, TOG, B_NODE_EXEC+node->nr, "Gamma",
1180 butr->xmin+dx, dy, dx, 19,
1181 &nbd->gamma, 0, 0, 0, 0, "Applies filter on gamma corrected values");
1183 uiBlockEndAlign(block);
1184 uiBlockBeginAlign(block);
1187 bt= uiDefButS(block, TOG, B_NOP, "Relative",
1188 butr->xmin, dy, dx*2, 19,
1189 &nbd->relative, 0, 0, 0, 0, "Use relative (percent) values to define blur radius");
1190 uiButSetFunc(bt, node_blur_relative_cb, node, NULL);
1194 bt= uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "X:",
1195 butr->xmin, dy, dx, 19,
1196 &nbd->percentx, 0.0f, 1.0f, 0, 0, "");
1197 uiButSetFunc(bt, node_blur_update_sizex_cb, node, NULL);
1198 bt= uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Y:",
1199 butr->xmin+dx, dy, dx, 19,
1200 &nbd->percenty, 0.0f, 1.0f, 0, 0, "");
1201 uiButSetFunc(bt, node_blur_update_sizey_cb, node, NULL);
1204 uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "X:",
1205 butr->xmin, dy, dx, 19,
1206 &nbd->sizex, 0, 256, 0, 0, "");
1207 uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "Y:",
1208 butr->xmin+dx, dy, dx, 19,
1209 &nbd->sizey, 0, 256, 0, 0, "");
1211 uiBlockEndAlign(block);
1216 static int node_composit_buts_dblur(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1219 NodeDBlurData *ndbd = node->storage;
1220 short dy = butr->ymin + 171;
1221 short dx = butr->xmax - butr->xmin;
1222 short halfdx= (short)dx/2;
1224 uiBlockBeginAlign(block);
1225 uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "Iterations:",
1226 butr->xmin, dy, dx, 19,
1227 &ndbd->iter, 1, 32, 10, 0, "Amount of iterations");
1228 uiDefButC(block, TOG, B_NODE_EXEC+node->nr, "Wrap",
1229 butr->xmin, dy-= 19, dx, 19,
1230 &ndbd->wrap, 0, 0, 0, 0, "Wrap blur");
1231 uiBlockEndAlign(block);
1235 uiDefBut(block, LABEL, B_NOP, "Center", butr->xmin, dy-= 19, dx, 19, NULL, 0.0f, 0.0f, 0, 0, "");
1237 uiBlockBeginAlign(block);
1238 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "X:",
1239 butr->xmin, dy-= 19, halfdx, 19,
1240 &ndbd->center_x, 0.0f, 1.0f, 10, 0, "X center in percents");
1241 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Y:",
1242 butr->xmin+halfdx, dy, halfdx, 19,
1243 &ndbd->center_y, 0.0f, 1.0f, 10, 0, "Y center in percents");
1244 uiBlockEndAlign(block);
1248 uiBlockBeginAlign(block);
1249 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Distance:",
1250 butr->xmin, dy-= 19, dx, 19,
1251 &ndbd->distance, -1.0f, 1.0f, 10, 0, "Amount of which the image moves");
1252 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Angle:",
1253 butr->xmin, dy-= 19, dx, 19,
1254 &ndbd->angle, 0.0f, 360.0f, 1000, 0, "Angle in which the image will be moved");
1255 uiBlockEndAlign(block);
1259 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Spin:",
1260 butr->xmin, dy-= 19, dx, 19,
1261 &ndbd->spin, -360.0f, 360.0f, 1000, 0, "Angle that is used to spin the image");
1265 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Zoom:",
1266 butr->xmin, dy-= 19, dx, 19,
1267 &ndbd->zoom, 0.0f, 100.0f, 100, 0, "Amount of which the image is zoomed");
1273 static int node_composit_buts_bilateralblur(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1276 NodeBilateralBlurData *nbbd= node->storage;
1277 short dy= butr->ymin+38;
1278 short dx= (butr->xmax-butr->xmin);
1280 uiBlockBeginAlign(block);
1281 uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "Iterations:",
1282 butr->xmin, dy, dx, 19,
1283 &nbbd->iter, 1, 128, 0, 0, "Amount of iterations");
1285 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Color Sigma:",
1286 butr->xmin, dy, dx, 19,
1287 &nbbd->sigma_color,0.01, 3, 10, 0, "Sigma value used to modify color");
1289 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Space Sigma:",
1290 butr->xmin, dy, dx, 19,
1291 &nbbd->sigma_space ,0.01, 30, 10, 0, "Sigma value used to modify space");
1297 /* qdn: defocus node */
1298 static int node_composit_buts_defocus(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1301 NodeDefocus *nqd = node->storage;
1302 short dy = butr->ymin + 209;
1303 short dx = butr->xmax - butr->xmin;
1304 char* mstr1 = "Bokeh Type%t|Octagon %x8|Heptagon %x7|Hexagon %x6|Pentagon %x5|Square %x4|Triangle %x3|Disk %x0";
1306 uiDefBut(block, LABEL, B_NOP, "Bokeh Type", butr->xmin, dy, dx, 19, NULL, 0, 0, 0, 0, "");
1307 uiDefButC(block, MENU, B_NODE_EXEC+node->nr, mstr1,
1308 butr->xmin, dy-19, dx, 19,
1309 &nqd->bktype, 0, 0, 0, 0, "Bokeh type");
1310 if (nqd->bktype) { /* for some reason rotating a disk doesn't seem to work... ;) */
1311 uiDefButC(block, NUM, B_NODE_EXEC+node->nr, "Rotate:",
1312 butr->xmin, dy-38, dx, 19,
1313 &nqd->rotation, 0, 90, 0, 0, "Bokeh shape rotation offset in degrees");
1315 uiDefButC(block, TOG, B_NODE_EXEC+node->nr, "Gamma Correct",
1316 butr->xmin, dy-57, dx, 19,
1317 &nqd->gamco, 0, 0, 0, 0, "Enable gamma correction before and after main process");
1318 if (nqd->no_zbuf==0) {
1319 // only needed for zbuffer input
1320 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "fStop:",
1321 butr->xmin, dy-76, dx, 19,
1322 &nqd->fstop, 0.5, 128, 10, 0, "Amount of focal blur, 128=infinity=perfect focus, half the value doubles the blur radius");
1324 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Maxblur:",
1325 butr->xmin, dy-95, dx, 19,
1326 &nqd->maxblur, 0, 10000, 1000, 0, "blur limit, maximum CoC radius, 0=no limit");
1327 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "BThreshold:",
1328 butr->xmin, dy-114, dx, 19,
1329 &nqd->bthresh, 0, 100, 100, 0, "CoC radius threshold, prevents background bleed on in-focus midground, 0=off");
1330 uiDefButC(block, TOG, B_NODE_EXEC+node->nr, "Preview",
1331 butr->xmin, dy-142, dx, 19,
1332 &nqd->preview, 0, 0, 0, 0, "Enable sampling mode, useful for preview when using low samplecounts");
1334 /* only visible when sampling mode enabled */
1335 uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "Samples:",
1336 butr->xmin, dy-161, dx, 19,
1337 &nqd->samples, 16, 256, 0, 0, "Number of samples (16=grainy, higher=less noise)");
1339 uiDefButS(block, TOG, B_NODE_EXEC+node->nr, "No zbuffer",
1340 butr->xmin, dy-190, dx, 19,
1341 &nqd->no_zbuf, 0, 0, 0, 0, "Enable when using an image as input instead of actual zbuffer (auto enabled if node not image based, eg. time node)");
1343 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Zscale:",
1344 butr->xmin, dy-209, dx, 19,
1345 &nqd->scale, 0, 1000, 100, 0, "Scales the Z input when not using a zbuffer, controls maximum blur designated by the color white or input value 1");
1352 /* qdn: glare node */
1353 static int node_composit_buts_glare(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1356 NodeGlare *ndg = node->storage;
1357 short dy = butr->ymin + 152, dx = butr->xmax - butr->xmin;
1358 char* mn1 = "Type%t|Ghosts%x3|Streaks%x2|Fog Glow%x1|Simple Star%x0";
1359 char* mn2 = "Quality/Speed%t|High/Slow%x0|Medium/Medium%x1|Low/Fast%x2";
1360 uiDefButC(block, MENU, B_NODE_EXEC+node->nr, mn1,
1361 butr->xmin, dy, dx, 19,
1362 &ndg->type, 0, 0, 0, 0, "Glow/Flare/Bloom type");
1363 uiDefButC(block, MENU, B_NODE_EXEC+node->nr, mn2,
1364 butr->xmin, dy-19, dx, 19,
1365 &ndg->quality, 0, 0, 0, 0,
1366 "Quality speed trade off, if not set to high quality, effect will be applied to low-res copy of source image");
1367 if (ndg->type != 1) {
1368 uiDefButC(block, NUM, B_NODE_EXEC+node->nr, "Iterations:",
1369 butr->xmin, dy-38, dx, 19,
1370 &ndg->iter, 2, 5, 1, 0,
1371 "higher values will generate longer/more streaks/ghosts");
1373 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "ColMod:",
1374 butr->xmin, dy-57, dx, 19,
1375 &ndg->colmod, 0, 1, 10, 0,
1376 "Amount of Color Modulation, modulates colors of streaks and ghosts for a spectral dispersion effect");
1378 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Mix:",
1379 butr->xmin, dy-76, dx, 19,
1380 &ndg->mix, -1, 1, 10, 0,
1381 "Mix balance, -1 is original image only, 0 is exact 50/50 mix, 1 is processed image only");
1382 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Threshold:",
1383 butr->xmin, dy-95, dx, 19,
1384 &ndg->threshold, 0, 1000, 10, 0,
1385 "Brightness threshold, the glarefilter will be applied only to pixels brighter than this value");
1386 if ((ndg->type == 2) || (ndg->type == 0))
1388 if (ndg->type == 2) {
1389 uiDefButC(block, NUM, B_NODE_EXEC+node->nr, "streaks:",
1390 butr->xmin, dy-114, dx, 19,
1391 &ndg->angle, 2, 16, 1000, 0,
1392 "Total number of streaks");
1393 uiDefButC(block, NUM, B_NODE_EXEC+node->nr, "AngOfs:",
1394 butr->xmin, dy-133, dx, 19,
1395 &ndg->angle_ofs, 0, 180, 1000, 0,
1396 "Streak angle rotation offset in degrees");
1398 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Fade:",
1399 butr->xmin, dy-152, dx, 19,
1400 &ndg->fade, 0.75, 1, 5, 0,
1401 "Streak fade out factor");
1404 uiDefButC(block, TOG, B_NODE_EXEC+node->nr, "Rot45",
1405 butr->xmin, dy-114, dx, 19,
1406 &ndg->angle, 0, 0, 0, 0,
1407 "simple star filter, add 45 degree rotation offset");
1408 if ((ndg->type == 1) || (ndg->type > 3)) // PBGH and fog glow
1409 uiDefButC(block, NUM, B_NODE_EXEC+node->nr, "Size:",
1410 butr->xmin, dy-114, dx, 19,
1411 &ndg->size, 6, 9, 1000, 0,
1412 "glow/glare size (not actual size, relative to initial size of bright area of pixels)");
1417 /* qdn: tonemap node */
1418 static int node_composit_buts_tonemap(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1421 NodeTonemap *ntm = node->storage;
1422 short dy = butr->ymin + 76, dx = butr->xmax - butr->xmin;
1423 char* mn = "Type%t|R/D Photoreceptor%x1|Rh Simple%x0";
1425 uiBlockBeginAlign(block);
1426 uiDefButI(block, MENU, B_NODE_EXEC+node->nr, mn,
1427 butr->xmin, dy, dx, 19,
1428 &ntm->type, 0, 0, 0, 0,
1429 "Tone mapping type");
1430 if (ntm->type == 0) {
1431 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Key:",
1432 butr->xmin, dy-19, dx, 19,
1433 &ntm->key, 0, 1, 5, 0,
1434 "The value the average luminance is mapped to");
1435 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Offset:",
1436 butr->xmin, dy-38, dx, 19,
1437 &ntm->offset, 0.001, 10, 5, 0,
1438 "Tonemap offset, normally always 1, but can be used as an extra control to alter the brightness curve");
1439 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Gamma:",
1440 butr->xmin, dy-57, dx, 19,
1441 &ntm->gamma, 0.001, 3, 5, 0,
1442 "Gamma factor, if not used, set to 1");
1445 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Intensity:",
1446 butr->xmin, dy-19, dx, 19,
1447 &ntm->f, -8, 8, 10, 0, "if less than zero, darkens image, otherwise makes it brighter");
1448 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Contrast:",
1449 butr->xmin, dy-38, dx, 19,
1450 &ntm->m, 0, 1, 5, 0, "Set to 0 to use estimate from input image");
1451 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Adaptation:",
1452 butr->xmin, dy-57, dx, 19,
1453 &ntm->a, 0, 1, 5, 0, "if 0, global, if 1, based on pixel intensity");
1454 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "ColCorrect:",
1455 butr->xmin, dy-76, dx, 19,
1456 &ntm->c, 0, 1, 5, 0, "color correction, if 0, same for all channels, if 1, each independent");
1458 uiBlockEndAlign(block);
1463 /* qdn: lens distortion node */
1464 static int node_composit_buts_lensdist(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1467 NodeLensDist *nld = node->storage;
1468 short dy = butr->ymin + 19, dx = butr->xmax - butr->xmin;
1469 uiBlockBeginAlign(block);
1470 uiDefButS(block, TOG, B_NODE_EXEC+node->nr, "Projector",
1471 butr->xmin, dy, dx, 19,
1472 &nld->proj, 0, 0, 0, 0,
1473 "Enable/disable projector mode, effect is applied in horizontal direction only");
1475 uiDefButS(block, TOG, B_NODE_EXEC+node->nr, "Jitter",
1476 butr->xmin, dy-19, dx/2, 19,
1477 &nld->jit, 0, 0, 0, 0,
1478 "Enable/disable jittering, faster, but also noisier");
1479 uiDefButS(block, TOG, B_NODE_EXEC+node->nr, "Fit",
1480 butr->xmin+dx/2, dy-19, dx/2, 19,
1481 &nld->fit, 0, 0, 0, 0,
1482 "For positive distortion factor only, scale image such that black areas are not visible");
1484 uiBlockEndAlign(block);
1490 static int node_composit_buts_vecblur(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1493 NodeBlurData *nbd= node->storage;
1494 short dy= butr->ymin;
1495 short dx= (butr->xmax-butr->xmin);
1497 uiBlockBeginAlign(block);
1498 uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "Samples:",
1499 butr->xmin, dy+76, dx, 19,
1500 &nbd->samples, 1, 256, 0, 0, "Amount of samples");
1501 uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "MinSpeed:",
1502 butr->xmin, dy+57, dx, 19,
1503 &nbd->minspeed, 0, 1024, 0, 0, "Minimum speed for a pixel to be blurred, used to separate background from foreground");
1504 uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "MaxSpeed:",
1505 butr->xmin, dy+38, dx, 19,
1506 &nbd->maxspeed, 0, 1024, 0, 0, "If not zero, maximum speed in pixels");
1507 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "BlurFac:",
1508 butr->xmin, dy+19, dx, 19,
1509 &nbd->fac, 0.0f, 2.0f, 10, 2, "Scaling factor for motion vectors, actually 'shutter speed' in frames");
1510 uiDefButS(block, TOG, B_NODE_EXEC+node->nr, "Curved",
1511 butr->xmin, dy, dx, 19,
1512 &nbd->curved, 0.0f, 2.0f, 10, 2, "Interpolate between frames in a bezier curve, rather than linearly");
1513 uiBlockEndAlign(block);
1518 static int node_composit_buts_filter(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1524 bt=uiDefButS(block, MENU, B_NODE_EXEC+node->nr, "Soften %x0|Sharpen %x1|Laplace %x2|Sobel %x3|Prewitt %x4|Kirsch %x5|Shadow %x6",
1525 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1526 &node->custom1, 0, 0, 0, 0, "");
1527 uiButSetFunc(bt, node_but_title_cb, node, bt);
1532 static int node_composit_buts_flip(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1538 bt=uiDefButS(block, MENU, B_NODE_EXEC+node->nr, "Flip X %x0|Flip Y %x1|Flip X & Y %x2",
1539 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1540 &node->custom1, 0, 0, 0, 0, "");
1541 uiButSetFunc(bt, node_but_title_cb, node, bt);
1546 static int node_composit_buts_crop(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1549 NodeTwoXYs *ntxy= node->storage;
1550 char elementheight = 19;
1551 short dx= (butr->xmax-butr->xmin)/2;
1552 short dy= butr->ymax - elementheight;
1553 short xymin= 0, xymax= 10000;
1555 uiBlockBeginAlign(block);
1557 /* crop image size toggle */
1558 uiDefButS(block, TOG, B_NODE_EXEC+node->nr, "Crop Image Size",
1559 butr->xmin, dy, dx*2, elementheight,
1560 &node->custom1, 0, 0, 0, 0, "Crop the size of the input image.");
1565 uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "X1:",
1566 butr->xmin, dy, dx, elementheight,
1567 &ntxy->x1, xymin, xymax, 0, 0, "");
1569 uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "Y1:",
1570 butr->xmin+dx, dy, dx, elementheight,
1571 &ntxy->y1, xymin, xymax, 0, 0, "");
1576 uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "X2:",
1577 butr->xmin, dy, dx, elementheight,
1578 &ntxy->x2, xymin, xymax, 0, 0, "");
1580 uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "Y2:",
1581 butr->xmin+dx, dy, dx, elementheight,
1582 &ntxy->y2, xymin, xymax, 0, 0, "");
1584 uiBlockEndAlign(block);
1589 static int node_composit_buts_splitviewer(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1592 uiBlockBeginAlign(block);
1594 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, "X",
1595 butr->xmin, butr->ymin+19, (butr->xmax-butr->xmin)/2, 20,
1596 &node->custom2, 0.0, 0.0, 0, 0, "");
1597 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, "Y",
1598 butr->xmin+(butr->xmax-butr->xmin)/2, butr->ymin+19, (butr->xmax-butr->xmin)/2, 20,
1599 &node->custom2, 0.0, 1.0, 0, 0, "");
1601 uiDefButS(block, NUMSLI, B_NODE_EXEC+node->nr, "Split %: ",
1602 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20, &node->custom1, 0, 100, 10, 0, "");
1607 static int node_composit_buts_map_value(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1610 TexMapping *texmap= node->storage;
1611 short xstart= (short)butr->xmin;
1612 short dy= (short)(butr->ymax-19.0f);
1613 short dx= (short)(butr->xmax-butr->xmin)/2;
1615 uiBlockBeginAlign(block);
1616 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Offs:", xstart, dy, 2*dx, 19, texmap->loc, -1000.0f, 1000.0f, 10, 2, "");
1618 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Size:", xstart, dy, 2*dx, 19, texmap->size, -1000.0f, 1000.0f, 10, 3, "");
1620 uiBlockBeginAlign(block);
1621 uiDefButBitI(block, TOG, TEXMAP_CLIP_MIN, B_NODE_EXEC+node->nr, "Min", xstart, dy, dx, 19, &texmap->flag, 0.0f, 0.0f, 0, 0, "");
1622 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "", xstart+dx, dy, dx, 19, texmap->min, -1000.0f, 1000.0f, 10, 2, "");
1624 uiDefButBitI(block, TOG, TEXMAP_CLIP_MAX, B_NODE_EXEC+node->nr, "Max", xstart, dy, dx, 19, &texmap->flag, 0.0f, 0.0f, 0, 0, "");
1625 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "", xstart+dx, dy, dx, 19, texmap->max, -1000.0f, 1000.0f, 10, 2, "");
1630 static int node_composit_buts_alphaover(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1633 NodeTwoFloats *ntf= node->storage;
1636 uiDefButS(block, TOG, B_NODE_EXEC+node->nr, "ConvertPremul",
1637 butr->xmin, butr->ymin+19, butr->xmax-butr->xmin, 19,
1638 &node->custom1, 0, 0, 0, 0, "");
1640 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Premul: ",
1641 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 19,
1642 &ntf->x, 0.0f, 1.0f, 100, 0, "");
1647 static int node_composit_buts_hue_sat(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1650 NodeHueSat *nhs= node->storage;
1652 uiBlockBeginAlign(block);
1653 uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Hue: ",
1654 butr->xmin, butr->ymin+40.0f, butr->xmax-butr->xmin, 20,
1655 &nhs->hue, 0.0f, 1.0f, 100, 0, "");
1656 uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Sat: ",
1657 butr->xmin, butr->ymin+20.0f, butr->xmax-butr->xmin, 20,
1658 &nhs->sat, 0.0f, 2.0f, 100, 0, "");
1659 uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Val: ",
1660 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1661 &nhs->val, 0.0f, 2.0f, 100, 0, "");
1666 static int node_composit_buts_dilateerode(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1669 uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "Distance:",
1670 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1671 &node->custom2, -100, 100, 0, 0, "Distance to grow/shrink (number of iterations)");
1676 static int node_composit_buts_diff_matte(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1679 short sx= (butr->xmax-butr->xmin)/4;
1680 short dx= (butr->xmax-butr->xmin)/3;
1681 NodeChroma *c= node->storage;
1683 uiBlockBeginAlign(block);
1684 /*color space selectors*/
1685 uiDefButS(block, ROW,B_NODE_EXEC+node->nr,"RGB",
1686 butr->xmin,butr->ymin+60,sx,20,
1687 &node->custom1,1,1, 0, 0, "RGB Color Space");
1688 uiDefButS(block, ROW,B_NODE_EXEC+node->nr,"HSV",
1689 butr->xmin+sx,butr->ymin+60,sx,20,
1690 &node->custom1,1,2, 0, 0, "HSV Color Space");
1691 uiDefButS(block, ROW,B_NODE_EXEC+node->nr,"YUV",
1692 butr->xmin+2*sx,butr->ymin+60,sx,20,
1693 &node->custom1,1,3, 0, 0, "YUV Color Space");
1694 uiDefButS(block, ROW,B_NODE_EXEC+node->nr,"YCC",
1695 butr->xmin+3*sx,butr->ymin+60,sx,20,
1696 &node->custom1,1,4, 0, 0, "YCbCr Color Space");
1697 /*channel tolorences*/
1698 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, " ",
1699 butr->xmin, butr->ymin+40, dx, 20,
1700 &c->t1, 0.0f, 1.0f, 100, 0, "Channel 1 Tolerance");
1701 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, " ",
1702 butr->xmin+dx, butr->ymin+40, dx, 20,
1703 &c->t2, 0.0f, 1.0f, 100, 0, "Channel 2 Tolorence");
1704 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, " ",
1705 butr->xmin+2*dx, butr->ymin+40, dx, 20,
1706 &c->t3, 0.0f, 1.0f, 100, 0, "Channel 3 Tolorence");
1707 /*falloff parameters*/
1709 uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Falloff Size ",
1710 butr->xmin, butr->ymin+20, butr->xmax-butr->xmin, 20,
1711 &c->fsize, 0.0f, 1.0f, 100, 0, "");
1713 uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Falloff: ",
1714 butr->xmin, butr->ymin+20, butr->xmax-butr->xmin, 20,
1715 &c->fstrength, 0.0f, 1.0f, 100, 0, "");
1720 static int node_composit_buts_color_spill(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1723 short dx= (butr->xmax-butr->xmin)/3;
1725 NodeChroma *c=node->storage;
1726 uiBlockBeginAlign(block);
1727 uiDefButF(block, NUM, B_NODE_EXEC+node->nr, "Enhance: ",
1728 butr->xmin, butr->ymin+20.0, butr->xmax-butr->xmin, 20,
1729 &c->t1, 0.0f, 0.5f, 100, 2, "Adjusts how much selected channel is affected by color spill algorithm");
1730 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, "R",
1731 butr->xmin,butr->ymin,dx,20,
1732 &node->custom1,1,1, 0, 0, "Red Spill Suppression");
1733 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, "G",
1734 butr->xmin+dx,butr->ymin,dx,20,
1735 &node->custom1,1,2, 0, 0, "Green Spill Suppression");
1736 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, "B",
1737 butr->xmin+2*dx,butr->ymin,dx,20,
1738 &node->custom1, 1, 3, 0, 0, "Blue Spill Suppression");
1739 uiBlockEndAlign(block);
1744 static int node_composit_buts_chroma_matte(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1747 short dx=(butr->xmax-butr->xmin)/2;
1748 NodeChroma *c= node->storage;
1749 uiBlockBeginAlign(block);
1751 uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Acceptance ",
1752 butr->xmin, butr->ymin+60, butr->xmax-butr->xmin, 20,
1753 &c->t1, 1.0f, 80.0f, 100, 0, "Tolerance for colors to be considered a keying color");
1754 uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Cutoff ",
1755 butr->xmin, butr->ymin+40, butr->xmax-butr->xmin, 20,
1756 &c->t2, 0.0f, 30.0f, 100, 0, "Colors below this will be considered as exact matches for keying color");
1758 uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Lift ",
1759 butr->xmin, butr->ymin+20, dx, 20,
1760 &c->fsize, 0.0f, 1.0f, 100, 0, "Alpha Lift");
1761 uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Gain ",
1762 butr->xmin+dx, butr->ymin+20, dx, 20,
1763 &c->fstrength, 0.0f, 1.0f, 100, 0, "Alpha Gain");
1765 uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Shadow Adjust ",
1766 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1767 &c->t3, 0.0f, 1.0f, 100, 0, "Adjusts the brightness of any shadows captured");
1775 static int node_composit_buts_channel_matte(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1778 short sx= (butr->xmax-butr->xmin)/4;
1779 short cx= (butr->xmax-butr->xmin)/3;
1780 NodeChroma *c=node->storage;
1783 /*color space selectors*/
1784 uiBlockBeginAlign(block);
1785 uiDefButS(block, ROW,B_NODE_EXEC+node->nr,"RGB",
1786 butr->xmin,butr->ymin+60,sx,20,&node->custom1,1,1, 0, 0, "RGB Color Space");
1787 uiDefButS(block, ROW,B_NODE_EXEC+node->nr,"HSV",
1788 butr->xmin+sx,butr->ymin+60,sx,20,&node->custom1,1,2, 0, 0, "HSV Color Space");
1789 uiDefButS(block, ROW,B_NODE_EXEC+node->nr,"YUV",
1790 butr->xmin+2*sx,butr->ymin+60,sx,20,&node->custom1,1,3, 0, 0, "YUV Color Space");
1791 uiDefButS(block, ROW,B_NODE_EXEC+node->nr,"YCC",
1792 butr->xmin+3*sx,butr->ymin+60,sx,20,&node->custom1,1,4, 0, 0, "YCbCr Color Space");
1794 if (node->custom1==1) {
1795 c1="R"; c2="G"; c3="B";
1797 else if(node->custom1==2){
1798 c1="H"; c2="S"; c3="V";
1800 else if(node->custom1==3){
1801 c1="Y"; c2="U"; c3="V";
1803 else { // if(node->custom1==4){
1804 c1="Y"; c2="Cb"; c3="Cr";
1807 /*channel selector */
1808 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, c1,
1809 butr->xmin,butr->ymin+40,cx,20,&node->custom2,1, 1, 0, 0, "Channel 1");
1810 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, c2,
1811 butr->xmin+cx,butr->ymin+40,cx,20,&node->custom2,1, 2, 0, 0, "Channel 2");
1812 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, c3,
1813 butr->xmin+cx+cx,butr->ymin+40,cx,20,&node->custom2, 1, 3, 0, 0, "Channel 3");
1815 /*tolerance sliders */
1816 uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "High ",
1817 butr->xmin, butr->ymin+20.0, butr->xmax-butr->xmin, 20,
1818 &c->t1, 0.0f, 1.0f, 100, 0, "Values higher than this setting are 100% opaque");
1819 uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Low ",
1820 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1821 &c->t2, 0.0f, 1.0f, 100, 0, "Values lower than this setting are 100% keyed");
1822 uiBlockEndAlign(block);
1824 /*keep t2 (low) less than t1 (high) */
1832 static int node_composit_buts_luma_matte(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1835 NodeChroma *c=node->storage;
1837 /*tolerance sliders */
1838 uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "High ",
1839 butr->xmin, butr->ymin+20.0, butr->xmax-butr->xmin, 20,
1840 &c->t1, 0.0f, 1.0f, 100, 0, "Values higher than this setting are 100% opaque");
1841 uiDefButF(block, NUMSLI, B_NODE_EXEC+node->nr, "Low ",
1842 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1843 &c->t2, 0.0f, 1.0f, 100, 0, "Values lower than this setting are 100% keyed");
1844 uiBlockEndAlign(block);
1846 /*keep t2 (low) less than t1 (high) */
1854 static int node_composit_buts_map_uv(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1857 uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "Alpha:",
1858 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1859 &node->custom1, 0, 100, 0, 0, "Conversion percentage of UV differences to Alpha");
1864 static int node_composit_buts_id_mask(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1867 uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "ID:",
1868 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1869 &node->custom1, 0, 10000, 0, 0, "Pass Index number to convert to Alpha");
1874 /* allocate sufficient! */
1875 static void node_imagetype_string(char *str)
1877 str += sprintf(str, "Save Image as: %%t|");
1878 str += sprintf(str, "Targa %%x%d|", R_TARGA);
1879 str += sprintf(str, "Targa Raw %%x%d|", R_RAWTGA);
1880 str += sprintf(str, "PNG %%x%d|", R_PNG);
1881 str += sprintf(str, "BMP %%x%d|", R_BMP);
1882 str += sprintf(str, "Jpeg %%x%d|", R_JPEG90);
1883 str += sprintf(str, "Iris %%x%d|", R_IRIS);
1884 str += sprintf(str, "Radiance HDR %%x%d|", R_RADHDR);
1885 str += sprintf(str, "Cineon %%x%d|", R_CINEON);
1886 str += sprintf(str, "DPX %%x%d|", R_DPX);
1887 str += sprintf(str, "OpenEXR %%x%d", R_OPENEXR);
1890 static void node_set_image_cb(bContext *C, void *ntree_v, void *node_v)
1892 bNodeTree *ntree= ntree_v;
1893 bNode *node= node_v;
1895 nodeSetActive(ntree, node);
1898 static int node_composit_buts_file_output(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1901 NodeImageFile *nif= node->storage;
1903 short x= (short)butr->xmin;
1904 short y= (short)butr->ymin;
1905 short w= (short)butr->xmax-butr->xmin;
1908 node_imagetype_string(str);
1910 uiBlockBeginAlign(block);
1912 bt = uiDefIconBut(block, BUT, B_NODE_SETIMAGE, ICON_FILESEL,
1914 0, 0, 0, 0, 0, "Open Fileselect to get Backbuf image");
1915 uiButSetFunc(bt, node_set_image_cb, ntree, node);
1917 uiDefBut(block, TEX, B_NOP, "",
1918 20+x, y+60, w-20, 20,
1919 nif->name, 0.0f, 240.0f, 0, 0, "");
1921 uiDefButS(block, MENU, B_NOP, str,
1923 &nif->imtype, 0.0f, 1.0f, 0, 0, "");
1925 if(nif->imtype==R_OPENEXR) {
1926 uiDefButBitS(block, TOG, R_OPENEXR_HALF, B_REDR, "Half",
1928 &nif->subimtype, 0, 0, 0, 0, "");
1930 uiDefButS(block, MENU,B_NOP, "Codec %t|None %x0|Pxr24 (lossy) %x1|ZIP (lossless) %x2|PIZ (lossless) %x3|RLE (lossless) %x4",
1931 x+w/2, y+20, w/2, 20,
1932 &nif->codec, 0, 0, 0, 0, "");
1935 uiDefButS(block, NUM, B_NOP, "Quality: ",
1937 &nif->quality, 10.0f, 100.0f, 10, 0, "");
1940 /* start frame, end frame */
1941 uiDefButI(block, NUM, B_NODE_EXEC+node->nr, "SFra: ",
1943 &nif->sfra, 1, MAXFRAMEF, 10, 0, "");
1944 uiDefButI(block, NUM, B_NODE_EXEC+node->nr, "EFra: ",
1946 &nif->efra, 1, MAXFRAMEF, 10, 0, "");
1952 static void node_scale_cb(bContext *C, void *node_v, void *unused_v)
1954 bNode *node= node_v;
1957 /* check the 2 inputs, and set them to reasonable values */
1958 for(nsock= node->inputs.first; nsock; nsock= nsock->next) {
1959 if(ELEM(node->custom1, CMP_SCALE_RELATIVE, CMP_SCALE_SCENEPERCENT))
1960 nsock->ns.vec[0]= 1.0;
1962 if(nsock->next==NULL)
1963 nsock->ns.vec[0]= (float)CTX_data_scene(C)->r.ysch;
1965 nsock->ns.vec[0]= (float)CTX_data_scene(C)->r.xsch;
1970 static int node_composit_buts_scale(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1973 uiBut *bt= uiDefButS(block, MENU, B_NODE_EXEC+node->nr, "Relative %x0|Absolute %x1|Scene Size % %x2|",
1974 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1975 &node->custom1, 0, 0, 0, 0, "Scale new image to absolute pixel size, size relative to the incoming image, or using the 'percent' size of the scene");
1976 uiButSetFunc(bt, node_scale_cb, node, NULL);
1981 static int node_composit_buts_invert(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1984 uiBlockBeginAlign(block);
1985 uiDefButBitS(block, TOG, CMP_CHAN_RGB, B_NODE_EXEC+node->nr, "RGB",
1986 butr->xmin, butr->ymin, (butr->xmax-butr->xmin)/2, 20,
1987 &node->custom1, 0, 0, 0, 0, "");
1988 uiDefButBitS(block, TOG, CMP_CHAN_A, B_NODE_EXEC+node->nr, "A",
1989 butr->xmin+(butr->xmax-butr->xmin)/2, butr->ymin, (butr->xmax-butr->xmin)/2, 20,
1990 &node->custom1, 0, 0, 0, 0, "");
1991 uiBlockEndAlign(block);
1996 static int node_composit_buts_premulkey(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
2002 bt=uiDefButS(block, MENU, B_NODE_EXEC+node->nr, "Key to Premul %x0|Premul to Key %x1",
2003 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
2004 &node->custom1, 0, 0, 0, 0, "Conversion between premultiplied alpha and key alpha");
2009 /* only once called */
2010 static void node_composit_set_butfunc(bNodeType *ntype)
2012 switch(ntype->type) {
2013 /* case NODE_GROUP: note, typeinfo for group is generated... see "XXX ugly hack" */
2015 case CMP_NODE_IMAGE:
2016 ntype->butfunc= node_composit_buts_image;
2018 case CMP_NODE_R_LAYERS:
2019 ntype->butfunc= node_composit_buts_renderlayers;
2021 case CMP_NODE_NORMAL:
2022 ntype->butfunc= node_buts_normal;
2024 case CMP_NODE_CURVE_VEC:
2025 ntype->butfunc= node_buts_curvevec;
2027 case CMP_NODE_CURVE_RGB:
2028 ntype->butfunc= node_buts_curvecol;
2030 case CMP_NODE_VALUE:
2031 ntype->butfunc= node_buts_value;
2034 ntype->butfunc= node_buts_rgb;
2037 ntype->butfunc= node_composit_buts_flip;
2039 case CMP_NODE_SPLITVIEWER:
2040 ntype->butfunc= node_composit_buts_splitviewer;
2042 case CMP_NODE_MIX_RGB:
2043 ntype->butfunc= node_buts_mix_rgb;
2045 case CMP_NODE_VALTORGB:
2046 ntype->butfunc= node_buts_valtorgb;
2049 ntype->butfunc= node_composit_buts_crop;
2052 ntype->butfunc= node_composit_buts_blur;
2054 case CMP_NODE_DBLUR:
2055 ntype->butfunc= node_composit_buts_dblur;
2057 case CMP_NODE_BILATERALBLUR:
2058 ntype->butfunc= node_composit_buts_bilateralblur;
2060 /* qdn: defocus node */
2061 case CMP_NODE_DEFOCUS:
2062 ntype->butfunc = node_composit_buts_defocus;
2064 /* qdn: glare node */
2065 case CMP_NODE_GLARE:
2066 ntype->butfunc = node_composit_buts_glare;
2068 /* qdn: tonemap node */
2069 case CMP_NODE_TONEMAP:
2070 ntype->butfunc = node_composit_buts_tonemap;
2072 /* qdn: lens distortion node */
2073 case CMP_NODE_LENSDIST:
2074 ntype->butfunc = node_composit_buts_lensdist;
2076 case CMP_NODE_VECBLUR:
2077 ntype->butfunc= node_composit_buts_vecblur;
2079 case CMP_NODE_FILTER:
2080 ntype->butfunc= node_composit_buts_filter;
2082 case CMP_NODE_MAP_VALUE:
2083 ntype->butfunc= node_composit_buts_map_value;
2086 ntype->butfunc= node_buts_time;
2088 case CMP_NODE_ALPHAOVER:
2089 ntype->butfunc= node_composit_buts_alphaover;
2091 case CMP_NODE_HUE_SAT:
2092 ntype->butfunc= node_composit_buts_hue_sat;
2094 case CMP_NODE_TEXTURE:
2095 ntype->butfunc= node_buts_texture;
2097 case CMP_NODE_DILATEERODE:
2098 ntype->butfunc= node_composit_buts_dilateerode;
2100 case CMP_NODE_OUTPUT_FILE:
2101 ntype->butfunc= node_composit_buts_file_output;
2104 case CMP_NODE_DIFF_MATTE:
2105 ntype->butfunc=node_composit_buts_diff_matte;
2107 case CMP_NODE_COLOR_SPILL:
2108 ntype->butfunc=node_composit_buts_color_spill;
2110 case CMP_NODE_CHROMA:
2111 ntype->butfunc=node_composit_buts_chroma_matte;
2113 case CMP_NODE_SCALE:
2114 ntype->butfunc= node_composit_buts_scale;
2116 case CMP_NODE_CHANNEL_MATTE:
2117 ntype->butfunc= node_composit_buts_channel_matte;
2119 case CMP_NODE_LUMA_MATTE:
2120 ntype->butfunc= node_composit_buts_luma_matte;
2122 case CMP_NODE_MAP_UV:
2123 ntype->butfunc= node_composit_buts_map_uv;
2125 case CMP_NODE_ID_MASK:
2126 ntype->butfunc= node_composit_buts_id_mask;
2129 ntype->butfunc= node_buts_math;
2131 case CMP_NODE_INVERT:
2132 ntype->butfunc= node_composit_buts_invert;
2134 case CMP_NODE_PREMULKEY:
2135 ntype->butfunc= node_composit_buts_premulkey;
2138 ntype->butfunc= NULL;
2142 /* ****************** BUTTON CALLBACKS FOR TEXTURE NODES ***************** */
2144 static int node_texture_buts_bricks(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
2147 short w = butr->xmax-butr->xmin;
2150 uiBlockBeginAlign(block);
2154 block, NUM, B_NODE_EXEC+node->nr, "Offset",
2155 butr->xmin, butr->ymin+20, w-ofw, 20,
2160 block, NUM, B_NODE_EXEC+node->nr, "",
2161 butr->xmin+w-ofw, butr->ymin+20, ofw, 20,
2164 "Offset every N rows" );
2168 block, NUM, B_NODE_EXEC+node->nr, "Squash",
2169 butr->xmin, butr->ymin+0, w-ofw, 20,
2174 block, NUM, B_NODE_EXEC+node->nr, "",
2175 butr->xmin+w-ofw, butr->ymin+0, ofw, 20,
2178 "Stretch every N rows" );
2180 uiBlockEndAlign(block);
2185 /* Copied from buttons_shading.c -- needs unifying */
2186 static char* noisebasis_menu()
2188 static char nbmenu[256];
2189 sprintf(nbmenu, "Noise Basis %%t|Blender Original %%x%d|Original Perlin %%x%d|Improved Perlin %%x%d|Voronoi F1 %%x%d|Voronoi F2 %%x%d|Voronoi F3 %%x%d|Voronoi F4 %%x%d|Voronoi F2-F1 %%x%d|Voronoi Crackle %%x%d|CellNoise %%x%d", TEX_BLENDER, TEX_STDPERLIN, TEX_NEWPERLIN, TEX_VORONOI_F1, TEX_VORONOI_F2, TEX_VORONOI_F3, TEX_VORONOI_F4, TEX_VORONOI_F2F1, TEX_VORONOI_CRACKLE, TEX_CELLNOISE);
2193 static int node_texture_buts_proc(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
2195 Tex *tex = (Tex *)node->storage;
2207 switch( tex->type ) {
2210 uiBlockBeginAlign( block );
2211 uiDefButS( block, MENU, B_NODE_EXEC+node->nr,
2212 "Linear %x0|Quad %x1|Ease %x2|Diag %x3|Sphere %x4|Halo %x5|Radial %x6",
2213 x, y+20, w, 20, &tex->stype, 0, 1, 0, 0, "Blend Type" );
2214 uiDefButBitS(block, TOG, TEX_FLIPBLEND, B_NODE_EXEC+node->nr, "Flip XY", x, y, w, 20,
2215 &tex->flag, 0, 0, 0, 0, "Flips the direction of the progression 90 degrees");
2216 uiBlockEndAlign( block );
2223 uiBlockBeginAlign(block);
2225 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, "Soft", 0*w/3+x, 40+y, w/3, 18, &tex->stype, 2.0, (float)TEX_SOFT, 0, 0, "Uses soft marble");
2226 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, "Sharp", 1*w/3+x, 40+y, w/3, 18, &tex->stype, 2.0, (float)TEX_SHARP, 0, 0, "Uses more clearly defined marble");
2227 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, "Sharper", 2*w/3+x, 40+y, w/3, 18, &tex->stype, 2.0, (float)TEX_SHARPER, 0, 0, "Uses very clearly defined marble");
2229 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, "Soft noise", 0*w/2+x, 20+y, w/2, 19, &tex->noisetype, 12.0, (float)TEX_NOISESOFT, 0, 0, "Generates soft noise");
2230 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, "Hard noise", 1*w/2+x, 20+y, w/2, 19, &tex->noisetype, 12.0, (float)TEX_NOISEPERL, 0, 0, "Generates hard noise");
2232 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, "Sin", 0*w/3+x, 0+y, w/3, 18, &tex->noisebasis2, 8.0, 0.0, 0, 0, "Uses a sine wave to produce bands.");
2233 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, "Saw", 1*w/3+x, 0+y, w/3, 18, &tex->noisebasis2, 8.0, 1.0, 0, 0, "Uses a saw wave to produce bands");
2234 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, "Tri", 2*w/3+x, 0+y, w/3, 18, &tex->noisebasis2, 8.0, 2.0, 0, 0, "Uses a triangle wave to produce bands");
2236 uiBlockEndAlign(block);
2242 uiDefButS(block, MENU, B_TEXPRV, noisebasis_menu(), x, y+64, w, 18, &tex->noisebasis, 0,0,0,0, "Sets the noise basis used for turbulence");
2244 uiBlockBeginAlign(block);
2245 uiDefButS(block, ROW, B_TEXPRV, "Bands", x, 40+y, w/2, 18, &tex->stype, 2.0, (float)TEX_BANDNOISE, 0, 0, "Uses standard noise");
2246 uiDefButS(block, ROW, B_TEXPRV, "Rings", w/2+x, 40+y, w/2, 18, &tex->stype, 2.0, (float)TEX_RINGNOISE, 0, 0, "Lets Noise return RGB value");
2248 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, "Sin", 0*w/3+x, 20+y, w/3, 18, &tex->noisebasis2, 8.0, (float)TEX_SIN, 0, 0, "Uses a sine wave to produce bands.");
2249 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, "Saw", 1*w/3+x, 20+y, w/3, 18, &tex->noisebasis2, 8.0, (float)TEX_SAW, 0, 0, "Uses a saw wave to produce bands");
2250 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, "Tri", 2*w/3+x, 20+y, w/3, 18, &tex->noisebasis2, 8.0, (float)TEX_TRI, 0, 0, "Uses a triangle wave to produce bands");
2252 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, "Soft noise", 0*w/2+x, 0+y, w/2, 19, &tex->noisetype, 12.0, (float)TEX_NOISESOFT, 0, 0, "Generates soft noise");
2253 uiDefButS(block, ROW, B_NODE_EXEC+node->nr, "Hard noise", 1*w/2+x, 0+y, w/2, 19, &tex->noisetype, 12.0, (float)TEX_NOISEPERL, 0, 0, "Generates hard noise");
2254 uiBlockEndAlign(block);
2260 uiDefButS(block, MENU, B_TEXPRV, noisebasis_menu(), x, y+60, w, 18, &tex->noisebasis, 0,0,0,0, "Sets the noise basis used for turbulence");
2262 uiBlockBeginAlign(block);
2263 uiDefButS(block, ROW, B_TEXPRV, "B/W", x, y+38, w/2, 18, &tex->stype, 2.0, (float)TEX_DEFAULT, 0, 0, "Uses standard noise");
2264 uiDefButS(block, ROW, B_TEXPRV, "Color", w/2+x, y+38, w/2, 18, &tex->stype, 2.0, (float)TEX_COLOR, 0, 0, "Lets Noise return RGB value");
2265 uiDefButS(block, ROW, B_TEXPRV, "Soft", x, y+20, w/2, 18, &tex->noisetype, 12.0, (float)TEX_NOISESOFT, 0, 0, "Generates soft noise");
2266 uiDefButS(block, ROW, B_TEXPRV, "Hard", w/2+x, y+20, w/2, 18, &tex->noisetype, 12.0, (float)TEX_NOISEPERL, 0, 0, "Generates hard noise");
2267 uiBlockEndAlign(block);
2269 uiDefButS(block, NUM, B_TEXPRV, "Depth:", x, y, w, 18, &tex->noisedepth, 0.0, 6.0, 0, 0, "Sets the depth of the cloud calculation");
2275 uiBlockBeginAlign(block);
2276 uiDefButS(block, MENU, B_TEXPRV, noisebasis_menu(), x, y+18, w, 18, &tex->noisebasis2, 0,0,0,0, "Sets the noise basis to distort");
2277 uiDefButS(block, MENU, B_TEXPRV, noisebasis_menu(), x, y, w, 18, &tex->noisebasis, 0,0,0,0, "Sets the noise basis which does the distortion");
2278 uiBlockEndAlign(block);
2285 static int node_texture_buts_image(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
2291 uiBlockBeginAlign(block);
2292 uiBlockSetCol(block, TH_BUT_SETTING2);
2295 IMAnames_to_pupstring(&strp, NULL, "LOAD NEW %x32767", &(G.main->image), NULL, NULL);
2297 bt= uiDefButS(block, MENU, B_NOP, strp,
2298 butr->xmin, butr->ymin, 19, 19,
2299 &node->menunr, 0, 0, 0, 0, "Browses existing choices");
2300 uiButSetFunc(bt, node_browse_image_cb, ntree, node);
2301 if(strp) MEM_freeN(strp);
2303 /* Add New button */
2304 if(node->id==NULL) {
2305 bt= uiDefBut(block, BUT, B_NODE_LOADIMAGE, "Load New",
2306 butr->xmin+19, butr->ymin, (short)(butr->xmax-butr->xmin-19.0f), 19,
2307 NULL, 0.0, 0.0, 0, 0, "Add new Image");
2308 uiButSetFunc(bt, node_active_cb, ntree, node);
2309 uiBlockSetCol(block, TH_AUTO);
2313 short xmin= (short)butr->xmin, xmax= (short)butr->xmax;
2314 short width= xmax - xmin - 19;
2316 bt= uiDefBut(block, TEX, B_NOP, "IM:",
2317 xmin+19, butr->ymin, width, 19,
2318 node->id->name+2, 0.0, 19.0, 0, 0, "Image name");
2319 uiButSetFunc(bt, node_ID_title_cb, node, NULL);
2325 static int node_texture_buts_output(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
2330 char *name = ((TexNodeOutput*)node->storage)->name;
2332 uiBlockBeginAlign(block);
2334 width = (short)(butr->xmax - butr->xmin);
2339 butr->xmin, butr->ymin,
2346 uiBlockEndAlign(block);
2351 /* only once called */
2352 static void node_texture_set_butfunc(bNodeType *ntype)
2354 if( ntype->type >= TEX_NODE_PROC && ntype->type < TEX_NODE_PROC_MAX ) {
2355 ntype->butfunc = node_texture_buts_proc;
2357 else switch(ntype->type) {
2360 ntype->butfunc = node_buts_math;
2363 case TEX_NODE_MIX_RGB:
2364 ntype->butfunc = node_buts_mix_rgb;
2367 case TEX_NODE_VALTORGB:
2368 ntype->butfunc = node_buts_valtorgb;
2371 case TEX_NODE_CURVE_RGB:
2372 ntype->butfunc= node_buts_curvecol;
2375 case TEX_NODE_CURVE_TIME:
2376 ntype->butfunc = node_buts_time;
2379 case TEX_NODE_TEXTURE:
2380 ntype->butfunc = node_buts_texture;
2383 case TEX_NODE_BRICKS:
2384 ntype->butfunc = node_texture_buts_bricks;
2387 case TEX_NODE_IMAGE:
2388 ntype->butfunc = node_texture_buts_image;
2391 case TEX_NODE_OUTPUT:
2392 ntype->butfunc = node_texture_buts_output;
2396 ntype->butfunc= NULL;
2400 /* ******* init draw callbacks for all tree types, only called in usiblender.c, once ************* */
2402 void init_node_butfuncs(void)
2407 ntype= node_all_shaders.first;
2409 node_shader_set_butfunc(ntype);
2412 /* composit nodes */
2413 ntype= node_all_composit.first;
2415 node_composit_set_butfunc(ntype);
2418 ntype = node_all_textures.first;
2420 node_texture_set_butfunc(ntype);
2425 /* ************** Generic drawing ************** */
2428 void node_rename_but(char *s)
2431 ListBase listb={0, 0};
2432 int dy, x1, y1, sizex=80, sizey=30;
2433 short pivot[2], mval[2], ret=0;
2435 getmouseco_sc(mval);
2437 pivot[0]= CLAMPIS(mval[0], (sizex+10), G.curscreen->sizex-30);
2438 pivot[1]= CLAMPIS(mval[1], (sizey/2)+10, G.curscreen->sizey-(sizey/2)-10);
2440 if (pivot[0]!=mval[0] || pivot[1]!=mval[1])
2441 warp_pointer(pivot[0], pivot[1]);
2443 mywinset(G.curscreen->mainwin);
2445 x1= pivot[0]-sizex+10;
2446 y1= pivot[1]-sizey/2;
2449 block= uiNewBlock(&listb, "button", UI_EMBOSS, UI_HELV, G.curscreen->mainwin);
2450 uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT|UI_BLOCK_ENTER_OK);
2452 /* buttons have 0 as return event, to prevent menu to close on hotkeys */
2453 uiBlockBeginAlign(block);
2455 uiDefBut(block, TEX, B_NOP, "Name: ", (short)(x1),(short)(y1+dy), 150, 19, s, 0.0, 19.0, 0, 0, "Node user name");
2457 uiBlockEndAlign(block);
2459 uiDefBut(block, BUT, 32767, "OK", (short)(x1+150), (short)(y1+dy), 29, 19, NULL, 0, 0, 0, 0, "");
2461 uiBoundsBlock(block, 2);
2463 ret= uiDoBlocks(&listb, 0, 0);
2468 void draw_nodespace_back_pix(ScrArea *sa, SpaceNode *snode)
2471 if((snode->flag & SNODE_BACKDRAW) && snode->treetype==NTREE_COMPOSIT) {
2472 Image *ima= BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
2473 ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
2476 /* somehow the offset has to be calculated inverse */
2478 //glaDefine2DArea(&sa->winrct);
2479 /* ortho at pixel level curarea */
2480 //myortho2(-0.375, sa->winx-0.375, -0.375, sa->winy-0.375);
2482 x = (sa->winx-ibuf->x)/2 + snode->xof;
2483 y = (sa->winy-ibuf->y)/2 + snode->yof;
2486 glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
2487 else if(ibuf->channels==4)
2488 glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_FLOAT, ibuf->rect_float);
2490 /* sort this out, this should not be needed */
2491 //myortho2(snode->v2d.cur.xmin, snode->v2d.cur.xmax, snode->v2d.cur.ymin, snode->v2d.cur.ymax);
2492 //bwin_clear_viewmat(sa->win); /* clear buttons view */
2493 // glLoadIdentity();
2499 /* note: needs to be userpref or opengl profile option */
2500 static void draw_nodespace_back_tex(ScrArea *sa, SpaceNode *snode)
2503 draw_nodespace_grid(snode);
2505 if(snode->flag & SNODE_BACKDRAW) {
2506 Image *ima= BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
2507 ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
2512 glMatrixMode(GL_PROJECTION);
2514 glMatrixMode(GL_MODELVIEW);
2517 glaDefine2DArea(&sa->winrct);
2519 if(ibuf->x > sa->winx || ibuf->y > sa->winy) {
2521 zoomx= (float)sa->winx/ibuf->x;
2522 zoomy= (float)sa->winy/ibuf->y;
2523 zoom = MIN2(zoomx, zoomy);
2526 x = (sa->winx-zoom*ibuf->x)/2 + snode->xof;
2527 y = (sa->winy-zoom*ibuf->y)/2 + snode->yof;
2529 glPixelZoom(zoom, zoom);
2531 glColor4f(1.0, 1.0, 1.0, 1.0);
2533 glaDrawPixelsTex(x, y, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
2534 else if(ibuf->channels==4)
2535 glaDrawPixelsTex(x, y, ibuf->x, ibuf->y, GL_FLOAT, ibuf->rect_float);
2537 glPixelZoom(1.0, 1.0);
2539 glMatrixMode(GL_PROJECTION);
2541 glMatrixMode(GL_MODELVIEW);
2548 void node_draw_link_bezier(View2D *v2d, float vec[4][3], int th_col1, int th_col2, int do_shaded)
2552 dist= 0.5f*ABS(vec[0][0] - vec[3][0]);
2555 /* check direction later, for top sockets */
2556 vec[1][0]= vec[0][0]+dist;
2557 vec[1][1]= vec[0][1];
2559 vec[2][0]= vec[3][0]-dist;
2560 vec[2][1]= vec[3][1];
2561 // printf("-> %f %f %f %f %f\n", dist, vec[0][0], vec[3][0], vec[1][0], vec[2][0]);
2563 if( MIN4(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) > v2d->cur.xmax); /* clipped */
2564 else if ( MAX4(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) < v2d->cur.xmin); /* clipped */
2566 float curve_res = 24, spline_step = 0.0f;
2568 /* we can reuse the dist variable here to increment the GL curve eval amount*/
2569 dist = 1.0f/curve_res;
2571 glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, vec[0]);
2572 glBegin(GL_LINE_STRIP);
2573 while (spline_step < 1.000001f) {
2575 UI_ThemeColorBlend(th_col1, th_col2, spline_step);
2576 glEvalCoord1f(spline_step);
2577 spline_step += dist;
2584 /* note; this is used for fake links in groups too */
2585 void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link)
2588 float mx=0.0f, my=0.0f;
2589 int do_shaded= 1, th_col1= TH_WIRE, th_col2= TH_WIRE;
2591 if(link->fromnode==NULL && link->tonode==NULL)
2594 /* XXX fix -> notifier thingymajiggle this is dragging link */
2595 if(link->fromnode==NULL || link->tonode==NULL) {
2597 // XXX getmouseco_areawin(mval);
2598 // XXX areamouseco_to_ipoco(v2d, mval, &mx, &my);
2599 UI_ThemeColor(TH_WIRE);
2603 /* going to give issues once... */
2604 if(link->tosock->flag & SOCK_UNAVAIL)
2606 if(link->fromsock->flag & SOCK_UNAVAIL)
2609 /* a bit ugly... but thats how we detect the internal group links */
2610 if(link->fromnode==link->tonode) {
2611 UI_ThemeColorBlend(TH_BACK, TH_WIRE, 0.25f);
2616 if(link->fromnode->level >= link->tonode->level && link->tonode->level!=0xFFF) {
2617 if(link->fromnode->flag & SELECT)
2618 th_col1= TH_EDGE_SELECT;
2619 if(link->tonode->flag & SELECT)
2620 th_col2= TH_EDGE_SELECT;
2623 UI_ThemeColor(TH_REDALERT);
2629 vec[0][2]= vec[1][2]= vec[2][2]= vec[3][2]= 0.0; /* only 2d spline, set the Z to 0*/
2631 /* in v0 and v3 we put begin/end points */
2632 if(link->fromnode) {
2633 vec[0][0]= link->fromsock->locx;
2634 vec[0][1]= link->fromsock->locy;
2641 vec[3][0]= link->tosock->locx;
2642 vec[3][1]= link->tosock->locy;
2649 node_draw_link_bezier(v2d, vec, th_col1, th_col2, do_shaded);
2650 // fdrawbezier(vec);
2655 static void nodes_panel_gpencil(short cntrl) // NODES_HANDLER_GREASEPENCIL
2660 snode= curarea->spacedata.first;
2662 block= uiNewBlock(&curarea->uiblocks, "nodes_panel_gpencil", UI_EMBOSS, UI_HELV, curarea->win);
2663 uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | cntrl);
2664 uiSetPanelHandler(NODES_HANDLER_GREASEPENCIL); // for close and esc
2665 if (uiNewPanel(curarea, block, "Grease Pencil", "SpaceNode", 100, 30, 318, 204)==0) return;
2667 /* we can only really draw stuff if there are nodes (otherwise no events are handled */
2668 if (snode->nodetree == NULL)
2671 /* allocate memory for gpd if drawing enabled (this must be done first or else we crash) */
2672 if (snode->flag & SNODE_DISPGP) {
2673 if (snode->gpd == NULL)
2674 gpencil_data_setactive(curarea, gpencil_data_addnew());
2677 if (snode->flag & SNODE_DISPGP) {
2678 bGPdata *gpd= snode->gpd;
2681 /* this is a variable height panel, newpanel doesnt force new size on existing panels */
2682 /* so first we make it default height */
2683 uiNewPanelHeight(block, 204);
2685 /* draw button for showing gpencil settings and drawings */
2686 uiDefButBitS(block, TOG, SNODE_DISPGP, B_REDR, "Use Grease Pencil", 10, 225, 150, 20, &snode->flag, 0, 0, 0, 0, "Display freehand annotations overlay over this Node Editor (draw using Shift-LMB)");
2688 /* extend the panel if the contents won't fit */
2689 newheight= draw_gpencil_panel(block, gpd, curarea);
2690 uiNewPanelHeight(block, newheight);
2693 uiDefButBitS(block, TOG, SNODE_DISPGP, B_REDR, "Use Grease Pencil", 10, 225, 150, 20, &snode->flag, 0, 0, 0, 0, "Display freehand annotations overlay over this Node Editor");
2694 uiDefBut(block, LABEL, 1, " ", 160, 180, 150, 20, NULL, 0.0, 0.0, 0, 0, "");
2698 static void nodes_blockhandlers(ScrArea *sa)
2700 SpaceNode *snode= sa->spacedata.first;
2703 for(a=0; a<SPACE_MAXHANDLER; a+=2) {
2704 switch(snode->blockhandler[a]) {
2705 case NODES_HANDLER_GREASEPENCIL:
2706 nodes_panel_gpencil(snode->blockhandler[a+1]);
2710 /* clear action value for event */
2711 snode->blockhandler[a+1]= 0;
2713 uiDrawBlocksPanels(sa, 0);