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_curve.h"
57 #include "BKE_global.h"
58 #include "BKE_image.h"
59 #include "BKE_library.h"
61 #include "BKE_material.h"
63 #include "BKE_object.h"
64 #include "BKE_texture.h"
66 #include "BKE_utildefines.h"
72 #include "BIF_glutil.h"
74 #include "MEM_guardedalloc.h"
77 #include "ED_space_api.h"
78 #include "ED_screen.h"
81 #include "RNA_access.h"
82 #include "RNA_define.h"
87 #include "UI_view2d.h"
88 #include "UI_interface.h"
89 #include "UI_resources.h"
91 #include "RE_pipeline.h"
92 #include "IMB_imbuf_types.h"
94 #include "node_intern.h"
97 /* autocomplete callback for buttons */
98 static void autocomplete_vcol(bContext *C, char *str, void *arg_v)
101 CustomDataLayer *layer;
102 AutoComplete *autocpl;
108 autocpl= autocomplete_begin(str, 32);
110 /* search if str matches the beginning of name */
111 for(me= G.main->mesh.first; me; me=me->id.next)
112 for(a=0, layer= me->fdata.layers; a<me->fdata.totlayer; a++, layer++)
113 if(layer->type == CD_MCOL)
114 autocomplete_do_name(autocpl, layer->name);
116 autocomplete_end(autocpl, str);
119 static int verify_valid_vcol_name(char *str)
122 CustomDataLayer *layer;
128 /* search if str matches the name */
129 for(me= G.main->mesh.first; me; me=me->id.next)
130 for(a=0, layer= me->fdata.layers; a<me->fdata.totlayer; a++, layer++)
131 if(layer->type == CD_MCOL)
132 if(strcmp(layer->name, str)==0)
138 /* ****************** GENERAL CALLBACKS FOR NODES ***************** */
140 static void node_ID_title_cb(bContext *C, void *node_v, void *unused_v)
145 test_idbutton(node->id->name+2); /* library.c, verifies unique name */
146 BLI_strncpy(node->name, node->id->name+2, 21);
151 static void node_but_title_cb(bContext *C, void *node_v, void *but_v)
153 // bNode *node= node_v;
154 // XXX uiBut *bt= but_v;
155 // XXX BLI_strncpy(node->name, bt->drawstr, NODE_MAXSTR);
157 // allqueue(REDRAWNODE, 0);
161 /* XXX not used yet, make compiler happy :) */
162 static void node_group_alone_cb(bContext *C, void *node_v, void *unused_v)
168 // allqueue(REDRAWNODE, 0);
171 /* ****************** BUTTON CALLBACKS FOR ALL TREES ***************** */
173 static int node_buts_group(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
175 if(block && node->id) {
179 uiBlockBeginAlign(block);
182 width= (short)(butr->xmax-butr->xmin - (node->id->us>1?19.0f:0.0f));
183 bt= uiDefBut(block, TEX, B_NOP, "NT:",
184 (short)butr->xmin, (short)butr->ymin, width, 19,
185 node->id->name+2, 0.0, 19.0, 0, 0, "NodeTree name");
186 uiButSetFunc(bt, node_ID_title_cb, node, NULL);
191 sprintf(str1, "%d", node->id->us);
192 bt= uiDefBut(block, BUT, B_NOP, str1,
193 (short)butr->xmax-19, (short)butr->ymin, 19, 19,
194 NULL, 0, 0, 0, 0, "Displays number of users.");
195 uiButSetFunc(bt, node_group_alone_cb, node, NULL);
198 uiBlockEndAlign(block);
204 static int node_buts_value(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
207 bNodeSocket *sock= node->outputs.first; /* first socket stores value */
209 uiDefButF(block, NUM, B_NODE_EXEC, "",
210 (short)butr->xmin, (short)butr->ymin, butr->xmax-butr->xmin, 20,
211 sock->ns.vec, sock->ns.min, sock->ns.max, 10, 2, "");
217 static int node_buts_rgb(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
220 bNodeSocket *sock= node->outputs.first; /* first socket stores value */
222 /* enforce square box drawing */
223 uiBlockSetEmboss(block, UI_EMBOSSP);
225 uiDefButF(block, HSVCUBE, B_NODE_EXEC, "",
226 (short)butr->xmin, (short)butr->ymin, butr->xmax-butr->xmin, 12,
227 sock->ns.vec, 0.0f, 1.0f, 3, 0, "");
228 uiDefButF(block, HSVCUBE, B_NODE_EXEC, "",
229 (short)butr->xmin, (short)butr->ymin+15, butr->xmax-butr->xmin, butr->ymax-butr->ymin -15 -15,
230 sock->ns.vec, 0.0f, 1.0f, 2, 0, "");
231 uiDefButF(block, COL, B_NOP, "",
232 (short)butr->xmin, (short)butr->ymax-12, butr->xmax-butr->xmin, 12,
233 sock->ns.vec, 0.0, 0.0, -1, 0, "");
234 /* the -1 above prevents col button to popup a color picker */
236 uiBlockSetEmboss(block, UI_EMBOSS);
239 return 30 + (int)(node->width-NODE_DY);
242 static int node_buts_mix_rgb(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
246 int a_but= (ntree->type==NTREE_COMPOSIT);
249 uiBlockBeginAlign(block);
250 bt=uiDefButS(block, MENU, B_NODE_EXEC, "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",
251 (short)butr->xmin, (short)butr->ymin, butr->xmax-butr->xmin -(a_but?20:0), 20,
252 &node->custom1, 0, 0, 0, 0, "");
253 uiButSetFunc(bt, node_but_title_cb, node, bt);
254 /* Alpha option, composite */
256 uiDefIconButS(block, TOG, B_NODE_EXEC, ICON_IMAGE_RGB_ALPHA,
257 (short)butr->xmax-20, (short)butr->ymin, 20, 20,
258 &node->custom2, 0, 0, 0, 0, "Include Alpha of 2nd input in this operation");
263 static int node_buts_time(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
266 CurveMapping *cumap= node->storage;
267 short dx= (short)((butr->xmax-butr->xmin)/2);
270 curvemap_buttons(block, node->storage, 's', B_NODE_EXEC, B_REDR, butr);
273 //cumap->flag |= CUMA_DRAW_CFRA;
274 //if(node->custom1<node->custom2)
275 // cumap->sample[0]= (float)(CFRA - node->custom1)/(float)(node->custom2-node->custom1);
278 uiBlockBeginAlign(block);
279 uiDefButS(block, NUM, B_NODE_EXEC, "Sta:",
280 (short)butr->xmin, (short)butr->ymin-22, dx, 19,
281 &node->custom1, 1.0, 20000.0, 0, 0, "Start frame");
282 uiDefButS(block, NUM, B_NODE_EXEC, "End:",
283 (short)butr->xmin+dx, (short)butr->ymin-22, dx, 19,
284 &node->custom2, 1.0, 20000.0, 0, 0, "End frame");
287 return node->width-NODE_DY;
290 static int node_buts_valtorgb(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
294 uiBlockColorbandButtons(block, node->storage, butr, B_NODE_EXEC);
300 static int node_buts_curvevec(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
303 curvemap_buttons(block, node->storage, 'v', B_NODE_EXEC, B_REDR, butr);
305 return (int)(node->width-NODE_DY);
308 static float *_sample_col= NULL; // bad bad, 2.5 will do better?
309 void node_curvemap_sample(float *col)
314 static int node_buts_curvecol(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
317 CurveMapping *cumap= node->storage;
319 cumap->flag |= CUMA_DRAW_SAMPLE;
320 VECCOPY(cumap->sample, _sample_col);
323 cumap->flag &= ~CUMA_DRAW_SAMPLE;
325 curvemap_buttons(block, node->storage, 'c', B_NODE_EXEC, B_REDR, butr);
327 return (int)(node->width-NODE_DY);
330 static int node_buts_normal(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
333 bNodeSocket *sock= node->outputs.first; /* first socket stores normal */
335 uiDefButF(block, BUT_NORMAL, B_NODE_EXEC, "",
336 (short)butr->xmin, (short)butr->ymin, butr->xmax-butr->xmin, butr->ymax-butr->ymin,
337 sock->ns.vec, 0.0f, 1.0f, 0, 0, "");
340 return (int)(node->width-NODE_DY);
343 static void node_browse_tex_cb(bContext *C, void *ntree_v, void *node_v)
345 bNodeTree *ntree= ntree_v;
349 if(node->menunr<1) return;
355 tex= BLI_findlink(&G.main->tex, node->menunr-1);
358 id_us_plus(node->id);
359 BLI_strncpy(node->name, node->id->name+2, 21);
361 nodeSetActive(ntree, node);
363 if( ntree->type == NTREE_TEXTURE )
364 ntreeTexCheckCyclics( ntree );
366 // allqueue(REDRAWBUTSSHADING, 0);
367 // allqueue(REDRAWNODE, 0);
368 NodeTagChanged(ntree, node);
373 static void node_dynamic_update_cb(bContext *C, void *ntree_v, void *node_v)
376 bNode *node= (bNode *)node_v;
380 if (BTST(node->custom1, NODE_DYNAMIC_ERROR)) error= 1;
382 /* Users only have to press the "update" button in one pynode
383 * and we also update all others sharing the same script */
384 for (ma= G.main->mat.first; ma; ma= ma->id.next) {
387 for (nd= ma->nodetree->nodes.first; nd; nd= nd->next) {
388 if ((nd->type == NODE_DYNAMIC) && (nd->id == id)) {
390 nd->custom1= BSET(nd->custom1, NODE_DYNAMIC_REPARSE);
393 nd->custom1= BSET(nd->custom1, NODE_DYNAMIC_ERROR);
399 // allqueue(REDRAWBUTSSHADING, 0);
400 // allqueue(REDRAWNODE, 0);
401 // XXX BIF_preview_changed(ID_MA);
404 static int node_buts_texture(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
408 ((Tex*)node->id)->use_nodes &&
409 (node->type != CMP_NODE_TEXTURE) &&
410 (node->type != TEX_NODE_TEXTURE)
416 short width = (short)(butr->xmax - butr->xmin);
418 /* browse button texture */
419 uiBlockBeginAlign(block);
420 IDnames_to_pupstring(&strp, NULL, "", &(G.main->tex), NULL, NULL);
422 bt= uiDefButS(block, MENU, B_NODE_EXEC, strp,
423 butr->xmin, butr->ymin+(multi?30:0), 20, 19,
424 &node->menunr, 0, 0, 0, 0, "Browse texture");
425 uiButSetFunc(bt, node_browse_tex_cb, ntree, node);
426 if(strp) MEM_freeN(strp);
429 bt= uiDefBut(block, TEX, B_NOP, "TE:",
430 butr->xmin+19, butr->ymin+(multi?30:0), butr->xmax-butr->xmin-19, 19,
431 node->id->name+2, 0.0, 19.0, 0, 0, "Texture name");
432 uiButSetFunc(bt, node_ID_title_cb, node, NULL);
434 uiBlockEndAlign(block);
437 char *menustr = ntreeTexOutputMenu(((Tex*)node->id)->nodetree);
438 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");
444 else return multi? 50: 20;
447 static int node_buts_math(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
452 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, "");
453 uiButSetFunc(bt, node_but_title_cb, node, bt);
459 /* ****************** BUTTON CALLBACKS FOR SHADER NODES ***************** */
461 static void node_browse_text_cb(bContext *C, void *ntree_v, void *node_v)
463 bNodeTree *ntree= ntree_v;
467 if(node->menunr<1) return;
473 node->id= BLI_findlink(&G.main->text, node->menunr-1);
474 id_us_plus(node->id);
475 BLI_strncpy(node->name, node->id->name+2, 21); /* huh? why 21? */
477 node->custom1= BSET(node->custom1, NODE_DYNAMIC_NEW);
479 nodeSetActive(ntree, node);
481 // allqueue(REDRAWBUTSSHADING, 0);
482 // allqueue(REDRAWNODE, 0);
487 static void node_mat_alone_cb(bContext *C, void *node_v, void *unused)
491 node->id= (ID *)copy_material((Material *)node->id);
493 //BIF_undo_push("Single user material");
494 // allqueue(REDRAWBUTSSHADING, 0);
495 // allqueue(REDRAWNODE, 0);
496 // allqueue(REDRAWOOPS, 0);
499 static void node_browse_mat_cb(bContext *C, void *ntree_v, void *node_v)
501 bNodeTree *ntree= ntree_v;
504 if(node->menunr<1) return;
506 if(node->menunr==32767) { /* code for Add New */
508 /* make copy, but make sure it doesnt have the node tag nor nodes */
509 Material *ma= (Material *)node->id;
511 ma= copy_material(ma);
514 ntreeFreeTree(ma->nodetree);
515 MEM_freeN(ma->nodetree);
520 else node->id= (ID *)add_material("MatNode");
523 if(node->id) node->id->us--;
524 node->id= BLI_findlink(&G.main->mat, node->menunr-1);
525 id_us_plus(node->id);
527 BLI_strncpy(node->name, node->id->name+2, 21);
529 nodeSetActive(ntree, node);
531 // allqueue(REDRAWBUTSSHADING, 0);
532 // allqueue(REDRAWNODE, 0);
533 // XXX BIF_preview_changed(ID_MA);
538 static void node_new_mat_cb(bContext *C, void *ntree_v, void *node_v)
540 bNodeTree *ntree= ntree_v;
543 node->id= (ID *)add_material("MatNode");
544 BLI_strncpy(node->name, node->id->name+2, 21);
546 nodeSetActive(ntree, node);
548 // allqueue(REDRAWBUTSSHADING, 0);
549 // allqueue(REDRAWNODE, 0);
550 // XXX BIF_preview_changed(ID_MA);
554 static void node_texmap_cb(bContext *C, void *texmap_v, void *unused_v)
556 init_mapping(texmap_v);
559 static int node_shader_buts_material(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
563 short dx= (short)((butr->xmax-butr->xmin)/3.0f), has_us= (node->id && node->id->us>1);
564 short dy= (short)butr->ymin;
567 /* WATCH IT: we use this callback in material buttons, but then only want first row */
568 if(butr->ymax-butr->ymin > 21.0f) dy+= 19;
570 uiBlockBeginAlign(block);
572 if(node->id==NULL) uiBlockSetCol(block, TH_REDALERT);
573 else if(has_us) uiBlockSetCol(block, TH_BUT_SETTING1);
574 else uiBlockSetCol(block, TH_BUT_SETTING2);
578 IDnames_to_pupstring(&strp, NULL, "ADD NEW %x32767", &(G.main->mat), NULL, NULL);
580 bt= uiDefButS(block, MENU, B_NOP, strp,
581 butr->xmin, dy, 19, 19,
582 &node->menunr, 0, 0, 0, 0, "Browses existing choices or adds NEW");
583 uiButSetFunc(bt, node_browse_mat_cb, ntree, node);
584 if(strp) MEM_freeN(strp);
588 bt= uiDefBut(block, BUT, B_NOP, "Add New",
589 butr->xmin+19, dy, (short)(butr->xmax-butr->xmin-19.0f), 19,
590 NULL, 0.0, 0.0, 0, 0, "Add new Material");
591 uiButSetFunc(bt, node_new_mat_cb, ntree, node);
595 short width= (short)(butr->xmax-butr->xmin-19.0f - (has_us?19.0f:0.0f));
596 bt= uiDefBut(block, TEX, B_NOP, "MA:",
597 butr->xmin+19, dy, width, 19,
598 node->id->name+2, 0.0, 19.0, 0, 0, "Material name");
599 uiButSetFunc(bt, node_ID_title_cb, node, NULL);
604 sprintf(str1, "%d", node->id->us);
605 bt= uiDefBut(block, BUT, B_NOP, str1,
606 butr->xmax-19, dy, 19, 19,
607 NULL, 0, 0, 0, 0, "Displays number of users. Click to make a single-user copy.");
608 uiButSetFunc(bt, node_mat_alone_cb, node, NULL);
611 /* WATCH IT: we use this callback in material buttons, but then only want first row */
612 if(butr->ymax-butr->ymin > 21.0f) {
614 uiDefButBitS(block, TOG, SH_NODE_MAT_DIFF, B_NODE_EXEC, "Diff",
615 butr->xmin, butr->ymin, dx, 19,
616 &node->custom1, 0, 0, 0, 0, "Material Node outputs Diffuse");
617 uiDefButBitS(block, TOG, SH_NODE_MAT_SPEC, B_NODE_EXEC, "Spec",
618 butr->xmin+dx, butr->ymin, dx, 19,
619 &node->custom1, 0, 0, 0, 0, "Material Node outputs Specular");
620 uiDefButBitS(block, TOG, SH_NODE_MAT_NEG, B_NODE_EXEC, "Neg Normal",
621 butr->xmax-dx, butr->ymin, dx, 19,
622 &node->custom1, 0, 0, 0, 0, "Material Node uses inverted Normal");
625 uiBlockEndAlign(block);
630 static int node_shader_buts_mapping(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
633 TexMapping *texmap= node->storage;
634 short dx= (short)((butr->xmax-butr->xmin)/7.0f);
635 short dy= (short)(butr->ymax-19);
637 uiBlockSetFunc(block, node_texmap_cb, texmap, NULL); /* all buttons get this */
639 uiBlockBeginAlign(block);
640 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+dx, dy, 2*dx, 19, texmap->loc, -1000.0f, 1000.0f, 10, 2, "");
641 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->loc+1, -1000.0f, 1000.0f, 10, 2, "");
642 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->loc+2, -1000.0f, 1000.0f, 10, 2, "");
644 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+dx, dy, 2*dx, 19, texmap->rot, -1000.0f, 1000.0f, 1000, 1, "");
645 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->rot+1, -1000.0f, 1000.0f, 1000, 1, "");
646 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->rot+2, -1000.0f, 1000.0f, 1000, 1, "");
648 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+dx, dy, 2*dx, 19, texmap->size, -1000.0f, 1000.0f, 10, 2, "");
649 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->size+1, -1000.0f, 1000.0f, 10, 2, "");
650 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->size+2, -1000.0f, 1000.0f, 10, 2, "");
652 uiBlockBeginAlign(block);
653 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+dx, dy, 2*dx, 19, texmap->min, -10.0f, 10.0f, 100, 2, "");
654 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->min+1, -10.0f, 10.0f, 100, 2, "");
655 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->min+2, -10.0f, 10.0f, 100, 2, "");
657 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+dx, dy, 2*dx, 19, texmap->max, -10.0f, 10.0f, 10, 2, "");
658 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->max+1, -10.0f, 10.0f, 10, 2, "");
659 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->max+2, -10.0f, 10.0f, 10, 2, "");
660 uiBlockEndAlign(block);
664 dy= (short)(butr->ymax-19);
665 uiDefBut(block, LABEL, B_NOP, "Loc", butr->xmin, dy, dx, 19, NULL, 0.0f, 0.0f, 0, 0, "");
667 uiDefBut(block, LABEL, B_NOP, "Rot", butr->xmin, dy, dx, 19, NULL, 0.0f, 0.0f, 0, 0, "");
669 uiDefBut(block, LABEL, B_NOP, "Size", butr->xmin, dy, dx, 19, NULL, 0.0f, 0.0f, 0, 0, "");
671 uiDefButBitI(block, TOG, TEXMAP_CLIP_MIN, B_NODE_EXEC, "Min", butr->xmin, dy, dx-4, 19, &texmap->flag, 0.0f, 0.0f, 0, 0, "");
673 uiDefButBitI(block, TOG, TEXMAP_CLIP_MAX, B_NODE_EXEC, "Max", butr->xmin, dy, dx-4, 19, &texmap->flag, 0.0f, 0.0f, 0, 0, "");
679 static int node_shader_buts_vect_math(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
684 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, "");
685 uiButSetFunc(bt, node_but_title_cb, node, bt);
690 static int node_shader_buts_geometry(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
694 NodeGeometry *ngeo= (NodeGeometry*)node->storage;
696 // XXX if(!verify_valid_uv_name(ngeo->uvname))
697 // XXX uiBlockSetCol(block, TH_REDALERT);
698 but= uiDefBut(block, TEX, B_NODE_EXEC, "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");
699 // XXX uiButSetCompleteFunc(but, autocomplete_uv, NULL);
701 if(!verify_valid_vcol_name(ngeo->colname));
702 // uiBlockSetCol(block, TH_REDALERT);
703 but= uiDefBut(block, TEX, B_NODE_EXEC, "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");
704 uiButSetCompleteFunc(but, autocomplete_vcol, NULL);
710 static int node_shader_buts_dynamic(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
714 // XXX SpaceNode *snode= curarea->spacedata.first;
715 short dy= (short)butr->ymin;
718 /* B_NODE_EXEC is handled in butspace.c do_node_buts */
721 IDnames_to_pupstring(&strp, NULL, "", &(G.main->text), NULL, NULL);
723 bt= uiDefButS(block, MENU, B_NODE_EXEC/*+node->nr*/, strp,
724 butr->xmin, dy, 19, 19,
725 &node->menunr, 0, 0, 0, 0, "Browses existing choices");
726 uiButSetFunc(bt, node_browse_text_cb, ntree, node);
728 if(strp) MEM_freeN(strp);
731 bt = uiDefBut(block, BUT, B_NOP, "Update",
732 butr->xmin+xoff, butr->ymin+20, 50, 19,
733 &node->menunr, 0.0, 19.0, 0, 0, "Refresh this node (and all others that use the same script)");
734 uiButSetFunc(bt, node_dynamic_update_cb, ntree, node);
736 if (BTST(node->custom1, NODE_DYNAMIC_ERROR)) {
737 // UI_ThemeColor(TH_REDALERT);
738 // XXX ui_rasterpos_safe(butr->xmin + xoff, butr->ymin + 5, snode->aspect);
739 // XXX snode_drawstring(snode, "Error! Check console...", butr->xmax - butr->xmin);
747 /* only once called */
748 static void node_shader_set_butfunc(bNodeType *ntype)
750 switch(ntype->type) {
751 /* case NODE_GROUP: note, typeinfo for group is generated... see "XXX ugly hack" */
753 case SH_NODE_MATERIAL:
754 case SH_NODE_MATERIAL_EXT:
755 ntype->butfunc= node_shader_buts_material;
757 case SH_NODE_TEXTURE:
758 ntype->butfunc= node_buts_texture;
761 ntype->butfunc= node_buts_normal;
763 case SH_NODE_CURVE_VEC:
764 ntype->butfunc= node_buts_curvevec;
766 case SH_NODE_CURVE_RGB:
767 ntype->butfunc= node_buts_curvecol;
769 case SH_NODE_MAPPING:
770 ntype->butfunc= node_shader_buts_mapping;
773 ntype->butfunc= node_buts_value;
776 ntype->butfunc= node_buts_rgb;
778 case SH_NODE_MIX_RGB:
779 ntype->butfunc= node_buts_mix_rgb;
781 case SH_NODE_VALTORGB:
782 ntype->butfunc= node_buts_valtorgb;
785 ntype->butfunc= node_buts_math;
787 case SH_NODE_VECT_MATH:
788 ntype->butfunc= node_shader_buts_vect_math;
790 case SH_NODE_GEOMETRY:
791 ntype->butfunc= node_shader_buts_geometry;
794 ntype->butfunc= node_shader_buts_dynamic;
797 ntype->butfunc= NULL;
801 /* ****************** BUTTON CALLBACKS FOR COMPOSITE NODES ***************** */
805 static void node_browse_image_cb(bContext *C, void *ntree_v, void *node_v)
807 bNodeTree *ntree= ntree_v;
810 nodeSetActive(ntree, node);
812 if(node->menunr<1) return;
813 if(node->menunr==32767) { /* code for Load New */
814 /// addqueue(curarea->win, UI_BUT_EVENT, B_NODE_LOADIMAGE); XXX
817 if(node->id) node->id->us--;
818 node->id= BLI_findlink(&G.main->image, node->menunr-1);
819 id_us_plus(node->id);
821 BLI_strncpy(node->name, node->id->name+2, 21);
823 NodeTagChanged(ntree, node);
824 BKE_image_signal((Image *)node->id, node->storage, IMA_SIGNAL_USER_NEW_IMAGE);
825 // addqueue(curarea->win, UI_BUT_EVENT, B_NODE_EXEC); XXX
830 static void node_active_cb(bContext *C, void *ntree_v, void *node_v)
832 nodeSetActive(ntree_v, node_v);
834 static void node_image_type_cb(bContext *C, void *node_v, void *unused)
837 // allqueue(REDRAWNODE, 1);
840 static char *node_image_type_pup(void)
842 char *str= MEM_mallocN(256, "image type pup");
847 a= sprintf(str, "Image Type %%t|");
848 a+= sprintf(str+a, " Image %%x%d %%i%d|", IMA_SRC_FILE, ICON_IMAGE_DATA);
849 a+= sprintf(str+a, " Movie %%x%d %%i%d|", IMA_SRC_MOVIE, ICON_SEQUENCE);
850 a+= sprintf(str+a, " Sequence %%x%d %%i%d|", IMA_SRC_SEQUENCE, ICON_IMAGE_COL);
851 a+= sprintf(str+a, " Generated %%x%d %%i%d", IMA_SRC_GENERATED, ICON_BLANK1);
856 /* copy from buttons_shading.c */
857 static char *layer_menu(RenderResult *rr)
860 int len= 40 + 40*BLI_countlist(&rr->layers);
862 char *str= MEM_callocN(len, "menu layers");
864 strcpy(str, "Layer %t");
866 for(nr=0, rl= rr->layers.first; rl; rl= rl->next, nr++) {
867 a+= sprintf(str+a, "|%s %%x%d", rl->name, nr);
873 static void image_layer_cb(bContext *C, void *ima_v, void *iuser_v)
875 Scene *scene= CTX_data_scene(C);
877 ntreeCompositForceHidden(scene->nodetree, scene);
878 BKE_image_multilayer_index(ima_v, iuser_v);
879 // allqueue(REDRAWNODE, 0);
882 static int node_composit_buts_image(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
884 ImageUser *iuser= node->storage;
888 short dy= (short)butr->ymax-19;
891 uiBlockBeginAlign(block);
894 IMAnames_to_pupstring(&strp, NULL, "LOAD NEW %x32767", &(G.main->image), NULL, NULL);
896 bt= uiDefButS(block, MENU, B_NOP, strp,
897 butr->xmin, dy, 19, 19,
898 &node->menunr, 0, 0, 0, 0, "Browses existing choices");
899 uiButSetFunc(bt, node_browse_image_cb, ntree, node);
900 if(strp) MEM_freeN(strp);
904 bt= uiDefBut(block, BUT, B_NODE_LOADIMAGE, "Load New",
905 butr->xmin+19, dy, (short)(butr->xmax-butr->xmin-19.0f), 19,
906 NULL, 0.0, 0.0, 0, 0, "Add new Image");
907 uiButSetFunc(bt, node_active_cb, ntree, node);
910 /* name button + type */
911 Image *ima= (Image *)node->id;
912 short xmin= (short)butr->xmin, xmax= (short)butr->xmax;
913 short width= xmax - xmin - 45;
914 short icon= ICON_IMAGE_DATA;
916 if(ima->source==IMA_SRC_MOVIE) icon= ICON_SEQUENCE;
917 else if(ima->source==IMA_SRC_SEQUENCE) icon= ICON_IMAGE_COL;
918 else if(ima->source==IMA_SRC_GENERATED) icon= ICON_BLANK1;
920 bt= uiDefBut(block, TEX, B_NOP, "IM:",
921 xmin+19, dy, width, 19,
922 node->id->name+2, 0.0, 19.0, 0, 0, "Image name");
923 uiButSetFunc(bt, node_ID_title_cb, node, NULL);
925 /* buffer type option */
926 strp= node_image_type_pup();
927 bt= uiDefIconTextButS(block, MENU, B_NOP, icon, strp,
929 &ima->source, 0.0, 19.0, 0, 0, "Image type");
930 uiButSetFunc(bt, node_image_type_cb, node, ima);
933 if( ELEM(ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE) ) {
934 width= (xmax-xmin)/2;
937 uiDefButI(block, NUM, B_NODE_EXEC, "Frs:",
939 &iuser->frames, 1.0, MAXFRAMEF, 0, 0, "Amount of images used in animation");
940 uiDefButI(block, NUM, B_NODE_EXEC, "SFra:",
941 xmin+width, dy, width, 19,
942 &iuser->sfra, 1.0, MAXFRAMEF, 0, 0, "Start frame of animation");
944 uiDefButI(block, NUM, B_NODE_EXEC, "Offs:",
946 &iuser->offset, -MAXFRAMEF, MAXFRAMEF, 0, 0, "Offsets the number of the frame to use in the animation");
947 uiDefButS(block, TOG, B_NODE_EXEC, "Cycl",
948 xmin+width, dy, width-20, 19,
949 &iuser->cycl, 0.0, 0.0, 0, 0, "Make animation go cyclic");
950 uiDefIconButBitS(block, TOG, IMA_ANIM_ALWAYS, B_NODE_EXEC, ICON_AUTO,
952 &iuser->flag, 0.0, 0.0, 0, 0, "Always refresh Image on frame changes");
954 if( ima->type==IMA_TYPE_MULTILAYER && ima->rr) {
955 RenderLayer *rl= BLI_findlink(&ima->rr->layers, iuser->layer);
959 strp= layer_menu(ima->rr);
960 bt= uiDefButS(block, MENU, B_NODE_EXEC, strp,
962 &iuser->layer, 0.0, 10000.0, 0, 0, "Layer");
963 uiButSetFunc(bt, image_layer_cb, ima->rr, node->storage);
971 Image *ima= (Image *)node->id;
974 /* for each draw we test for anim refresh event */
975 if(iuser->flag & IMA_ANIM_REFRESHED) {
976 iuser->flag &= ~IMA_ANIM_REFRESHED;
977 // addqueue(curarea->win, UI_BUT_EVENT, B_NODE_EXEC); XXX
980 if( ELEM(ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE) )
982 if( ima->type==IMA_TYPE_MULTILAYER)
990 /* if we use render layers from other scene, we make a nice title */
991 static void set_render_layers_title(bContext *C, void *node_v, void *unused)
995 SceneRenderLayer *srl;
999 BLI_strncpy(str, node->id->name+2, 21);
1001 sce= (Scene *)node->id;
1005 sce= CTX_data_scene(C);
1007 srl= BLI_findlink(&sce->r.layers, node->custom1);
1010 srl= sce->r.layers.first;
1013 strcat(str, srl->name);
1014 BLI_strncpy(node->name, str, 32);
1017 static char *scene_layer_menu(Scene *sce)
1019 SceneRenderLayer *srl;
1020 int len= 40 + 40*BLI_countlist(&sce->r.layers);
1022 char *str= MEM_callocN(len, "menu layers");
1024 strcpy(str, "Active Layer %t");
1026 for(nr=0, srl= sce->r.layers.first; srl; srl= srl->next, nr++) {
1027 a+= sprintf(str+a, "|%s %%x%d", srl->name, nr);
1033 static void node_browse_scene_cb(bContext *C, void *ntree_v, void *node_v)
1035 bNodeTree *ntree= ntree_v;
1036 bNode *node= node_v;
1039 if(node->menunr<1) return;
1045 sce= BLI_findlink(&G.main->scene, node->menunr-1);
1047 id_us_plus(node->id);
1049 set_render_layers_title(C, node, NULL);
1050 nodeSetActive(ntree, node);
1052 // allqueue(REDRAWBUTSSHADING, 0);
1053 // allqueue(REDRAWNODE, 0);
1054 NodeTagChanged(ntree, node);
1060 static int node_composit_buts_renderlayers(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1062 if(block && node->id) {
1063 Scene *scene= (Scene *)node->id;
1067 /* browse button scene */
1068 uiBlockBeginAlign(block);
1069 IDnames_to_pupstring(&strp, NULL, "", &(G.main->scene), NULL, NULL);
1071 bt= uiDefButS(block, MENU, B_NOP, strp,
1072 butr->xmin, butr->ymin, 20, 19,
1073 &node->menunr, 0, 0, 0, 0, "Browse Scene to use RenderLayer from");
1074 uiButSetFunc(bt, node_browse_scene_cb, ntree, node);
1075 if(strp) MEM_freeN(strp);
1077 /* browse button layer */
1078 strp= scene_layer_menu(node->id?(Scene *)node->id:scene);
1080 bt= uiDefIconTextButS(block, MENU, B_NODE_EXEC, ICON_RENDERLAYERS, strp,
1081 butr->xmin+20, butr->ymin, (butr->xmax-butr->xmin)-40, 19,
1082 &node->custom1, 0, 0, 0, 0, "Choose Render Layer");
1084 bt= uiDefButS(block, MENU, B_NODE_EXEC, strp,
1085 butr->xmin+20, butr->ymin, (butr->xmax-butr->xmin)-40, 19,
1086 &node->custom1, 0, 0, 0, 0, "Choose Render Layer");
1087 uiButSetFunc(bt, set_render_layers_title, node, NULL);
1091 /* uses custom2, not the best implementation of the world... but we need it to work now :) */
1092 bt= uiDefIconButS(block, TOG, B_NODE_EXEC, ICON_SCENE,
1093 butr->xmax-20, butr->ymin, 20, 19,
1094 &node->custom2, 0, 0, 0, 0, "Re-render this Layer");
1100 static void node_blur_relative_cb(bContext *C, void *node, void *poin2)
1103 NodeBlurData *nbd= nodev->storage;
1104 if(nbd->image_in_width != 0){
1105 if(nbd->relative){ /* convert absolute values to relative */
1106 nbd->percentx= (float)(nbd->sizex)/nbd->image_in_width;
1107 nbd->percenty= (float)(nbd->sizey)/nbd->image_in_height;
1108 }else{ /* convert relative values to absolute */
1109 nbd->sizex= (int)(nbd->percentx*nbd->image_in_width);
1110 nbd->sizey= (int)(nbd->percenty*nbd->image_in_height);
1113 // allqueue(REDRAWNODE, 0);
1115 static void node_blur_update_sizex_cb(bContext *C, void *node, void *poin2)
1118 NodeBlurData *nbd= nodev->storage;
1120 nbd->sizex= (int)(nbd->percentx*nbd->image_in_width);
1122 static void node_blur_update_sizey_cb(bContext *C, void *node, void *poin2)
1125 NodeBlurData *nbd= nodev->storage;
1127 nbd->sizey= (int)(nbd->percenty*nbd->image_in_height);
1129 static int node_composit_buts_blur(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1132 NodeBlurData *nbd= node->storage;
1134 short dy= butr->ymin+58;
1135 short dx= (butr->xmax-butr->xmin)/2;
1138 uiBlockBeginAlign(block);
1139 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);
1140 uiDefButS(block, MENU, B_NODE_EXEC,str,
1141 butr->xmin, dy, dx*2, 19,
1142 &nbd->filtertype, 0, 0, 0, 0, "Set sampling filter for blur");
1144 if (nbd->filtertype != R_FILTER_FAST_GAUSS) {
1145 uiDefButC(block, TOG, B_NODE_EXEC, "Bokeh",
1146 butr->xmin, dy, dx, 19,
1147 &nbd->bokeh, 0, 0, 0, 0, "Uses circular filter, warning it's slow!");
1148 uiDefButC(block, TOG, B_NODE_EXEC, "Gamma",
1149 butr->xmin+dx, dy, dx, 19,
1150 &nbd->gamma, 0, 0, 0, 0, "Applies filter on gamma corrected values");
1152 uiBlockEndAlign(block);
1153 uiBlockBeginAlign(block);
1156 bt= uiDefButS(block, TOG, B_NOP, "Relative",
1157 butr->xmin, dy, dx*2, 19,
1158 &nbd->relative, 0, 0, 0, 0, "Use relative (percent) values to define blur radius");
1159 uiButSetFunc(bt, node_blur_relative_cb, node, NULL);
1163 bt= uiDefButF(block, NUM, B_NODE_EXEC, "X:",
1164 butr->xmin, dy, dx, 19,
1165 &nbd->percentx, 0.0f, 1.0f, 0, 0, "");
1166 uiButSetFunc(bt, node_blur_update_sizex_cb, node, NULL);
1167 bt= uiDefButF(block, NUM, B_NODE_EXEC, "Y:",
1168 butr->xmin+dx, dy, dx, 19,
1169 &nbd->percenty, 0.0f, 1.0f, 0, 0, "");
1170 uiButSetFunc(bt, node_blur_update_sizey_cb, node, NULL);
1173 uiDefButS(block, NUM, B_NODE_EXEC, "X:",
1174 butr->xmin, dy, dx, 19,
1175 &nbd->sizex, 0, 256, 0, 0, "");
1176 uiDefButS(block, NUM, B_NODE_EXEC, "Y:",
1177 butr->xmin+dx, dy, dx, 19,
1178 &nbd->sizey, 0, 256, 0, 0, "");
1180 uiBlockEndAlign(block);
1185 static int node_composit_buts_dblur(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1188 NodeDBlurData *ndbd = node->storage;
1189 short dy = butr->ymin + 171;
1190 short dx = butr->xmax - butr->xmin;
1191 short halfdx= (short)dx/2;
1193 uiBlockBeginAlign(block);
1194 uiDefButS(block, NUM, B_NODE_EXEC, "Iterations:",
1195 butr->xmin, dy, dx, 19,
1196 &ndbd->iter, 1, 32, 10, 0, "Amount of iterations");
1197 uiDefButC(block, TOG, B_NODE_EXEC, "Wrap",
1198 butr->xmin, dy-= 19, dx, 19,
1199 &ndbd->wrap, 0, 0, 0, 0, "Wrap blur");
1200 uiBlockEndAlign(block);
1204 uiDefBut(block, LABEL, B_NOP, "Center", butr->xmin, dy-= 19, dx, 19, NULL, 0.0f, 0.0f, 0, 0, "");
1206 uiBlockBeginAlign(block);
1207 uiDefButF(block, NUM, B_NODE_EXEC, "X:",
1208 butr->xmin, dy-= 19, halfdx, 19,
1209 &ndbd->center_x, 0.0f, 1.0f, 10, 0, "X center in percents");
1210 uiDefButF(block, NUM, B_NODE_EXEC, "Y:",
1211 butr->xmin+halfdx, dy, halfdx, 19,
1212 &ndbd->center_y, 0.0f, 1.0f, 10, 0, "Y center in percents");
1213 uiBlockEndAlign(block);
1217 uiBlockBeginAlign(block);
1218 uiDefButF(block, NUM, B_NODE_EXEC, "Distance:",
1219 butr->xmin, dy-= 19, dx, 19,
1220 &ndbd->distance, -1.0f, 1.0f, 10, 0, "Amount of which the image moves");
1221 uiDefButF(block, NUM, B_NODE_EXEC, "Angle:",
1222 butr->xmin, dy-= 19, dx, 19,
1223 &ndbd->angle, 0.0f, 360.0f, 1000, 0, "Angle in which the image will be moved");
1224 uiBlockEndAlign(block);
1228 uiDefButF(block, NUM, B_NODE_EXEC, "Spin:",
1229 butr->xmin, dy-= 19, dx, 19,
1230 &ndbd->spin, -360.0f, 360.0f, 1000, 0, "Angle that is used to spin the image");
1234 uiDefButF(block, NUM, B_NODE_EXEC, "Zoom:",
1235 butr->xmin, dy-= 19, dx, 19,
1236 &ndbd->zoom, 0.0f, 100.0f, 100, 0, "Amount of which the image is zoomed");
1242 static int node_composit_buts_bilateralblur(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1245 NodeBilateralBlurData *nbbd= node->storage;
1246 short dy= butr->ymin+38;
1247 short dx= (butr->xmax-butr->xmin);
1249 uiBlockBeginAlign(block);
1250 uiDefButS(block, NUM, B_NODE_EXEC, "Iterations:",
1251 butr->xmin, dy, dx, 19,
1252 &nbbd->iter, 1, 128, 0, 0, "Amount of iterations");
1254 uiDefButF(block, NUM, B_NODE_EXEC, "Color Sigma:",
1255 butr->xmin, dy, dx, 19,
1256 &nbbd->sigma_color,0.01, 3, 10, 0, "Sigma value used to modify color");
1258 uiDefButF(block, NUM, B_NODE_EXEC, "Space Sigma:",
1259 butr->xmin, dy, dx, 19,
1260 &nbbd->sigma_space ,0.01, 30, 10, 0, "Sigma value used to modify space");
1266 /* qdn: defocus node */
1267 static int node_composit_buts_defocus(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1270 NodeDefocus *nqd = node->storage;
1271 short dy = butr->ymin + 209;
1272 short dx = butr->xmax - butr->xmin;
1273 char* mstr1 = "Bokeh Type%t|Octagon %x8|Heptagon %x7|Hexagon %x6|Pentagon %x5|Square %x4|Triangle %x3|Disk %x0";
1275 uiDefBut(block, LABEL, B_NOP, "Bokeh Type", butr->xmin, dy, dx, 19, NULL, 0, 0, 0, 0, "");
1276 uiDefButC(block, MENU, B_NODE_EXEC, mstr1,
1277 butr->xmin, dy-19, dx, 19,
1278 &nqd->bktype, 0, 0, 0, 0, "Bokeh type");
1279 if (nqd->bktype) { /* for some reason rotating a disk doesn't seem to work... ;) */
1280 uiDefButC(block, NUM, B_NODE_EXEC, "Rotate:",
1281 butr->xmin, dy-38, dx, 19,
1282 &nqd->rotation, 0, 90, 0, 0, "Bokeh shape rotation offset in degrees");
1284 uiDefButC(block, TOG, B_NODE_EXEC, "Gamma Correct",
1285 butr->xmin, dy-57, dx, 19,
1286 &nqd->gamco, 0, 0, 0, 0, "Enable gamma correction before and after main process");
1287 if (nqd->no_zbuf==0) {
1288 // only needed for zbuffer input
1289 uiDefButF(block, NUM, B_NODE_EXEC, "fStop:",
1290 butr->xmin, dy-76, dx, 19,
1291 &nqd->fstop, 0.5, 128, 10, 0, "Amount of focal blur, 128=infinity=perfect focus, half the value doubles the blur radius");
1293 uiDefButF(block, NUM, B_NODE_EXEC, "Maxblur:",
1294 butr->xmin, dy-95, dx, 19,
1295 &nqd->maxblur, 0, 10000, 1000, 0, "blur limit, maximum CoC radius, 0=no limit");
1296 uiDefButF(block, NUM, B_NODE_EXEC, "BThreshold:",
1297 butr->xmin, dy-114, dx, 19,
1298 &nqd->bthresh, 0, 100, 100, 0, "CoC radius threshold, prevents background bleed on in-focus midground, 0=off");
1299 uiDefButC(block, TOG, B_NODE_EXEC, "Preview",
1300 butr->xmin, dy-142, dx, 19,
1301 &nqd->preview, 0, 0, 0, 0, "Enable sampling mode, useful for preview when using low samplecounts");
1303 /* only visible when sampling mode enabled */
1304 uiDefButS(block, NUM, B_NODE_EXEC, "Samples:",
1305 butr->xmin, dy-161, dx, 19,
1306 &nqd->samples, 16, 256, 0, 0, "Number of samples (16=grainy, higher=less noise)");
1308 uiDefButS(block, TOG, B_NODE_EXEC, "No zbuffer",
1309 butr->xmin, dy-190, dx, 19,
1310 &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)");
1312 uiDefButF(block, NUM, B_NODE_EXEC, "Zscale:",
1313 butr->xmin, dy-209, dx, 19,
1314 &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");
1321 /* qdn: glare node */
1322 static int node_composit_buts_glare(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1325 NodeGlare *ndg = node->storage;
1326 short dy = butr->ymin + 152, dx = butr->xmax - butr->xmin;
1327 char* mn1 = "Type%t|Ghosts%x3|Streaks%x2|Fog Glow%x1|Simple Star%x0";
1328 char* mn2 = "Quality/Speed%t|High/Slow%x0|Medium/Medium%x1|Low/Fast%x2";
1329 uiDefButC(block, MENU, B_NODE_EXEC, mn1,
1330 butr->xmin, dy, dx, 19,
1331 &ndg->type, 0, 0, 0, 0, "Glow/Flare/Bloom type");
1332 uiDefButC(block, MENU, B_NODE_EXEC, mn2,
1333 butr->xmin, dy-19, dx, 19,
1334 &ndg->quality, 0, 0, 0, 0,
1335 "Quality speed trade off, if not set to high quality, effect will be applied to low-res copy of source image");
1336 if (ndg->type != 1) {
1337 uiDefButC(block, NUM, B_NODE_EXEC, "Iterations:",
1338 butr->xmin, dy-38, dx, 19,
1339 &ndg->iter, 2, 5, 1, 0,
1340 "higher values will generate longer/more streaks/ghosts");
1342 uiDefButF(block, NUM, B_NODE_EXEC, "ColMod:",
1343 butr->xmin, dy-57, dx, 19,
1344 &ndg->colmod, 0, 1, 10, 0,
1345 "Amount of Color Modulation, modulates colors of streaks and ghosts for a spectral dispersion effect");
1347 uiDefButF(block, NUM, B_NODE_EXEC, "Mix:",
1348 butr->xmin, dy-76, dx, 19,
1349 &ndg->mix, -1, 1, 10, 0,
1350 "Mix balance, -1 is original image only, 0 is exact 50/50 mix, 1 is processed image only");
1351 uiDefButF(block, NUM, B_NODE_EXEC, "Threshold:",
1352 butr->xmin, dy-95, dx, 19,
1353 &ndg->threshold, 0, 1000, 10, 0,
1354 "Brightness threshold, the glarefilter will be applied only to pixels brighter than this value");
1355 if ((ndg->type == 2) || (ndg->type == 0))
1357 if (ndg->type == 2) {
1358 uiDefButC(block, NUM, B_NODE_EXEC, "streaks:",
1359 butr->xmin, dy-114, dx, 19,
1360 &ndg->angle, 2, 16, 1000, 0,
1361 "Total number of streaks");
1362 uiDefButC(block, NUM, B_NODE_EXEC, "AngOfs:",
1363 butr->xmin, dy-133, dx, 19,
1364 &ndg->angle_ofs, 0, 180, 1000, 0,
1365 "Streak angle rotation offset in degrees");
1367 uiDefButF(block, NUM, B_NODE_EXEC, "Fade:",
1368 butr->xmin, dy-152, dx, 19,
1369 &ndg->fade, 0.75, 1, 5, 0,
1370 "Streak fade out factor");
1373 uiDefButC(block, TOG, B_NODE_EXEC, "Rot45",
1374 butr->xmin, dy-114, dx, 19,
1375 &ndg->angle, 0, 0, 0, 0,
1376 "simple star filter, add 45 degree rotation offset");
1377 if ((ndg->type == 1) || (ndg->type > 3)) // PBGH and fog glow
1378 uiDefButC(block, NUM, B_NODE_EXEC, "Size:",
1379 butr->xmin, dy-114, dx, 19,
1380 &ndg->size, 6, 9, 1000, 0,
1381 "glow/glare size (not actual size, relative to initial size of bright area of pixels)");
1386 /* qdn: tonemap node */
1387 static int node_composit_buts_tonemap(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1390 NodeTonemap *ntm = node->storage;
1391 short dy = butr->ymin + 76, dx = butr->xmax - butr->xmin;
1392 char* mn = "Type%t|R/D Photoreceptor%x1|Rh Simple%x0";
1394 uiBlockBeginAlign(block);
1395 uiDefButI(block, MENU, B_NODE_EXEC, mn,
1396 butr->xmin, dy, dx, 19,
1397 &ntm->type, 0, 0, 0, 0,
1398 "Tone mapping type");
1399 if (ntm->type == 0) {
1400 uiDefButF(block, NUM, B_NODE_EXEC, "Key:",
1401 butr->xmin, dy-19, dx, 19,
1402 &ntm->key, 0, 1, 5, 0,
1403 "The value the average luminance is mapped to");
1404 uiDefButF(block, NUM, B_NODE_EXEC, "Offset:",
1405 butr->xmin, dy-38, dx, 19,
1406 &ntm->offset, 0.001, 10, 5, 0,
1407 "Tonemap offset, normally always 1, but can be used as an extra control to alter the brightness curve");
1408 uiDefButF(block, NUM, B_NODE_EXEC, "Gamma:",
1409 butr->xmin, dy-57, dx, 19,
1410 &ntm->gamma, 0.001, 3, 5, 0,
1411 "Gamma factor, if not used, set to 1");
1414 uiDefButF(block, NUM, B_NODE_EXEC, "Intensity:",
1415 butr->xmin, dy-19, dx, 19,
1416 &ntm->f, -8, 8, 10, 0, "if less than zero, darkens image, otherwise makes it brighter");
1417 uiDefButF(block, NUM, B_NODE_EXEC, "Contrast:",
1418 butr->xmin, dy-38, dx, 19,
1419 &ntm->m, 0, 1, 5, 0, "Set to 0 to use estimate from input image");
1420 uiDefButF(block, NUM, B_NODE_EXEC, "Adaptation:",
1421 butr->xmin, dy-57, dx, 19,
1422 &ntm->a, 0, 1, 5, 0, "if 0, global, if 1, based on pixel intensity");
1423 uiDefButF(block, NUM, B_NODE_EXEC, "ColCorrect:",
1424 butr->xmin, dy-76, dx, 19,
1425 &ntm->c, 0, 1, 5, 0, "color correction, if 0, same for all channels, if 1, each independent");
1427 uiBlockEndAlign(block);
1432 /* qdn: lens distortion node */
1433 static int node_composit_buts_lensdist(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1436 NodeLensDist *nld = node->storage;
1437 short dy = butr->ymin + 19, dx = butr->xmax - butr->xmin;
1438 uiBlockBeginAlign(block);
1439 uiDefButS(block, TOG, B_NODE_EXEC, "Projector",
1440 butr->xmin, dy, dx, 19,
1441 &nld->proj, 0, 0, 0, 0,
1442 "Enable/disable projector mode, effect is applied in horizontal direction only");
1444 uiDefButS(block, TOG, B_NODE_EXEC, "Jitter",
1445 butr->xmin, dy-19, dx/2, 19,
1446 &nld->jit, 0, 0, 0, 0,
1447 "Enable/disable jittering, faster, but also noisier");
1448 uiDefButS(block, TOG, B_NODE_EXEC, "Fit",
1449 butr->xmin+dx/2, dy-19, dx/2, 19,
1450 &nld->fit, 0, 0, 0, 0,
1451 "For positive distortion factor only, scale image such that black areas are not visible");
1453 uiBlockEndAlign(block);
1459 static int node_composit_buts_vecblur(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1462 NodeBlurData *nbd= node->storage;
1463 short dy= butr->ymin;
1464 short dx= (butr->xmax-butr->xmin);
1466 uiBlockBeginAlign(block);
1467 uiDefButS(block, NUM, B_NODE_EXEC, "Samples:",
1468 butr->xmin, dy+76, dx, 19,
1469 &nbd->samples, 1, 256, 0, 0, "Amount of samples");
1470 uiDefButS(block, NUM, B_NODE_EXEC, "MinSpeed:",
1471 butr->xmin, dy+57, dx, 19,
1472 &nbd->minspeed, 0, 1024, 0, 0, "Minimum speed for a pixel to be blurred, used to separate background from foreground");
1473 uiDefButS(block, NUM, B_NODE_EXEC, "MaxSpeed:",
1474 butr->xmin, dy+38, dx, 19,
1475 &nbd->maxspeed, 0, 1024, 0, 0, "If not zero, maximum speed in pixels");
1476 uiDefButF(block, NUM, B_NODE_EXEC, "Blur:",
1477 butr->xmin, dy+19, dx, 19,
1478 &nbd->fac, 0.0f, 2.0f, 10, 2, "Scaling factor for motion vectors, actually 'shutter speed' in frames");
1479 uiDefButS(block, TOG, B_NODE_EXEC, "Curved",
1480 butr->xmin, dy, dx, 19,
1481 &nbd->curved, 0.0f, 2.0f, 10, 2, "Interpolate between frames in a bezier curve, rather than linearly");
1482 uiBlockEndAlign(block);
1487 static int node_composit_buts_filter(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1493 bt=uiDefButS(block, MENU, B_NODE_EXEC, "Soften %x0|Sharpen %x1|Laplace %x2|Sobel %x3|Prewitt %x4|Kirsch %x5|Shadow %x6",
1494 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1495 &node->custom1, 0, 0, 0, 0, "");
1496 uiButSetFunc(bt, node_but_title_cb, node, bt);
1501 static int node_composit_buts_flip(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1507 bt=uiDefButS(block, MENU, B_NODE_EXEC, "Flip X %x0|Flip Y %x1|Flip X & Y %x2",
1508 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1509 &node->custom1, 0, 0, 0, 0, "");
1510 uiButSetFunc(bt, node_but_title_cb, node, bt);
1515 static int node_composit_buts_crop(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1518 NodeTwoXYs *ntxy= node->storage;
1519 char elementheight = 19;
1520 short dx= (butr->xmax-butr->xmin)/2;
1521 short dy= butr->ymax - elementheight;
1522 short xymin= 0, xymax= 10000;
1524 uiBlockBeginAlign(block);
1526 /* crop image size toggle */
1527 uiDefButS(block, TOG, B_NODE_EXEC, "Crop Image Size",
1528 butr->xmin, dy, dx*2, elementheight,
1529 &node->custom1, 0, 0, 0, 0, "Crop the size of the input image.");
1534 uiDefButS(block, NUM, B_NODE_EXEC, "X1:",
1535 butr->xmin, dy, dx, elementheight,
1536 &ntxy->x1, xymin, xymax, 0, 0, "");
1538 uiDefButS(block, NUM, B_NODE_EXEC, "Y1:",
1539 butr->xmin+dx, dy, dx, elementheight,
1540 &ntxy->y1, xymin, xymax, 0, 0, "");
1545 uiDefButS(block, NUM, B_NODE_EXEC, "X2:",
1546 butr->xmin, dy, dx, elementheight,
1547 &ntxy->x2, xymin, xymax, 0, 0, "");
1549 uiDefButS(block, NUM, B_NODE_EXEC, "Y2:",
1550 butr->xmin+dx, dy, dx, elementheight,
1551 &ntxy->y2, xymin, xymax, 0, 0, "");
1553 uiBlockEndAlign(block);
1558 static int node_composit_buts_splitviewer(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1561 uiBlockBeginAlign(block);
1563 uiDefButS(block, ROW, B_NODE_EXEC, "X",
1564 butr->xmin, butr->ymin+19, (butr->xmax-butr->xmin)/2, 20,
1565 &node->custom2, 0.0, 0.0, 0, 0, "");
1566 uiDefButS(block, ROW, B_NODE_EXEC, "Y",
1567 butr->xmin+(butr->xmax-butr->xmin)/2, butr->ymin+19, (butr->xmax-butr->xmin)/2, 20,
1568 &node->custom2, 0.0, 1.0, 0, 0, "");
1570 uiDefButS(block, NUMSLI, B_NODE_EXEC, "Split %: ",
1571 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20, &node->custom1, 0, 100, 10, 0, "");
1576 static int node_composit_buts_map_value(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1579 TexMapping *texmap= node->storage;
1580 short xstart= (short)butr->xmin;
1581 short dy= (short)(butr->ymax-19.0f);
1582 short dx= (short)(butr->xmax-butr->xmin)/2;
1584 uiBlockBeginAlign(block);
1585 uiDefButF(block, NUM, B_NODE_EXEC, "Offs:", xstart, dy, 2*dx, 19, texmap->loc, -1000.0f, 1000.0f, 10, 2, "");
1587 uiDefButF(block, NUM, B_NODE_EXEC, "Size:", xstart, dy, 2*dx, 19, texmap->size, -1000.0f, 1000.0f, 10, 3, "");
1589 uiBlockBeginAlign(block);
1590 uiDefButBitI(block, TOG, TEXMAP_CLIP_MIN, B_NODE_EXEC, "Min", xstart, dy, dx, 19, &texmap->flag, 0.0f, 0.0f, 0, 0, "");
1591 uiDefButF(block, NUM, B_NODE_EXEC, "", xstart+dx, dy, dx, 19, texmap->min, -1000.0f, 1000.0f, 10, 2, "");
1593 uiDefButBitI(block, TOG, TEXMAP_CLIP_MAX, B_NODE_EXEC, "Max", xstart, dy, dx, 19, &texmap->flag, 0.0f, 0.0f, 0, 0, "");
1594 uiDefButF(block, NUM, B_NODE_EXEC, "", xstart+dx, dy, dx, 19, texmap->max, -1000.0f, 1000.0f, 10, 2, "");
1599 static int node_composit_buts_alphaover(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1602 NodeTwoFloats *ntf= node->storage;
1605 uiDefButS(block, TOG, B_NODE_EXEC, "ConvertPremul",
1606 butr->xmin, butr->ymin+19, butr->xmax-butr->xmin, 19,
1607 &node->custom1, 0, 0, 0, 0, "");
1609 uiDefButF(block, NUM, B_NODE_EXEC, "Premul: ",
1610 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 19,
1611 &ntf->x, 0.0f, 1.0f, 100, 0, "");
1616 static int node_composit_buts_hue_sat(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1619 NodeHueSat *nhs= node->storage;
1621 uiBlockBeginAlign(block);
1622 uiDefButF(block, NUMSLI, B_NODE_EXEC, "Hue: ",
1623 butr->xmin, butr->ymin+40.0f, butr->xmax-butr->xmin, 20,
1624 &nhs->hue, 0.0f, 1.0f, 100, 0, "");
1625 uiDefButF(block, NUMSLI, B_NODE_EXEC, "Sat: ",
1626 butr->xmin, butr->ymin+20.0f, butr->xmax-butr->xmin, 20,
1627 &nhs->sat, 0.0f, 2.0f, 100, 0, "");
1628 uiDefButF(block, NUMSLI, B_NODE_EXEC, "Val: ",
1629 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1630 &nhs->val, 0.0f, 2.0f, 100, 0, "");
1635 static int node_composit_buts_dilateerode(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1638 uiDefButS(block, NUM, B_NODE_EXEC, "Distance:",
1639 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1640 &node->custom2, -100, 100, 0, 0, "Distance to grow/shrink (number of iterations)");
1645 static int node_composit_buts_diff_matte(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1648 short sx= (butr->xmax-butr->xmin)/4;
1649 short dx= (butr->xmax-butr->xmin)/3;
1650 NodeChroma *c= node->storage;
1652 uiBlockBeginAlign(block);
1653 /*color space selectors*/
1654 uiDefButS(block, ROW,B_NODE_EXEC,"RGB",
1655 butr->xmin,butr->ymin+60,sx,20,
1656 &node->custom1,1,1, 0, 0, "RGB Color Space");
1657 uiDefButS(block, ROW,B_NODE_EXEC,"HSV",
1658 butr->xmin+sx,butr->ymin+60,sx,20,
1659 &node->custom1,1,2, 0, 0, "HSV Color Space");
1660 uiDefButS(block, ROW,B_NODE_EXEC,"YUV",
1661 butr->xmin+2*sx,butr->ymin+60,sx,20,
1662 &node->custom1,1,3, 0, 0, "YUV Color Space");
1663 uiDefButS(block, ROW,B_NODE_EXEC,"YCC",
1664 butr->xmin+3*sx,butr->ymin+60,sx,20,
1665 &node->custom1,1,4, 0, 0, "YCbCr Color Space");
1666 /*channel tolorences*/
1667 uiDefButF(block, NUM, B_NODE_EXEC, " ",
1668 butr->xmin, butr->ymin+40, dx, 20,
1669 &c->t1, 0.0f, 1.0f, 100, 0, "Channel 1 Tolerance");
1670 uiDefButF(block, NUM, B_NODE_EXEC, " ",
1671 butr->xmin+dx, butr->ymin+40, dx, 20,
1672 &c->t2, 0.0f, 1.0f, 100, 0, "Channel 2 Tolorence");
1673 uiDefButF(block, NUM, B_NODE_EXEC, " ",
1674 butr->xmin+2*dx, butr->ymin+40, dx, 20,
1675 &c->t3, 0.0f, 1.0f, 100, 0, "Channel 3 Tolorence");
1676 /*falloff parameters*/
1678 uiDefButF(block, NUMSLI, B_NODE_EXEC, "Falloff Size ",
1679 butr->xmin, butr->ymin+20, butr->xmax-butr->xmin, 20,
1680 &c->fsize, 0.0f, 1.0f, 100, 0, "");
1682 uiDefButF(block, NUMSLI, B_NODE_EXEC, "Falloff: ",
1683 butr->xmin, butr->ymin+20, butr->xmax-butr->xmin, 20,
1684 &c->fstrength, 0.0f, 1.0f, 100, 0, "");
1689 static int node_composit_buts_color_spill(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1692 short dx= (butr->xmax-butr->xmin)/3;
1694 NodeChroma *c=node->storage;
1695 uiBlockBeginAlign(block);
1696 uiDefButF(block, NUM, B_NODE_EXEC, "Enhance: ",
1697 butr->xmin, butr->ymin+20.0, butr->xmax-butr->xmin, 20,
1698 &c->t1, 0.0f, 0.5f, 100, 2, "Adjusts how much selected channel is affected by color spill algorithm");
1699 uiDefButS(block, ROW, B_NODE_EXEC, "R",
1700 butr->xmin,butr->ymin,dx,20,
1701 &node->custom1,1,1, 0, 0, "Red Spill Suppression");
1702 uiDefButS(block, ROW, B_NODE_EXEC, "G",
1703 butr->xmin+dx,butr->ymin,dx,20,
1704 &node->custom1,1,2, 0, 0, "Green Spill Suppression");
1705 uiDefButS(block, ROW, B_NODE_EXEC, "B",
1706 butr->xmin+2*dx,butr->ymin,dx,20,
1707 &node->custom1, 1, 3, 0, 0, "Blue Spill Suppression");
1708 uiBlockEndAlign(block);
1713 static int node_composit_buts_chroma_matte(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1716 short dx=(butr->xmax-butr->xmin)/2;
1717 NodeChroma *c= node->storage;
1718 uiBlockBeginAlign(block);
1720 uiDefButF(block, NUMSLI, B_NODE_EXEC, "Acceptance ",
1721 butr->xmin, butr->ymin+60, butr->xmax-butr->xmin, 20,
1722 &c->t1, 1.0f, 80.0f, 100, 0, "Tolerance for colors to be considered a keying color");
1723 uiDefButF(block, NUMSLI, B_NODE_EXEC, "Cutoff ",
1724 butr->xmin, butr->ymin+40, butr->xmax-butr->xmin, 20,
1725 &c->t2, 0.0f, 30.0f, 100, 0, "Colors below this will be considered as exact matches for keying color");
1727 uiDefButF(block, NUMSLI, B_NODE_EXEC, "Lift ",
1728 butr->xmin, butr->ymin+20, dx, 20,
1729 &c->fsize, 0.0f, 1.0f, 100, 0, "Alpha Lift");
1730 uiDefButF(block, NUMSLI, B_NODE_EXEC, "Gain ",
1731 butr->xmin+dx, butr->ymin+20, dx, 20,
1732 &c->fstrength, 0.0f, 1.0f, 100, 0, "Alpha Gain");
1734 uiDefButF(block, NUMSLI, B_NODE_EXEC, "Shadow Adjust ",
1735 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1736 &c->t3, 0.0f, 1.0f, 100, 0, "Adjusts the brightness of any shadows captured");
1744 static int node_composit_buts_channel_matte(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1747 short sx= (butr->xmax-butr->xmin)/4;
1748 short cx= (butr->xmax-butr->xmin)/3;
1749 NodeChroma *c=node->storage;
1752 /*color space selectors*/
1753 uiBlockBeginAlign(block);
1754 uiDefButS(block, ROW,B_NODE_EXEC,"RGB",
1755 butr->xmin,butr->ymin+60,sx,20,&node->custom1,1,1, 0, 0, "RGB Color Space");
1756 uiDefButS(block, ROW,B_NODE_EXEC,"HSV",
1757 butr->xmin+sx,butr->ymin+60,sx,20,&node->custom1,1,2, 0, 0, "HSV Color Space");
1758 uiDefButS(block, ROW,B_NODE_EXEC,"YUV",
1759 butr->xmin+2*sx,butr->ymin+60,sx,20,&node->custom1,1,3, 0, 0, "YUV Color Space");
1760 uiDefButS(block, ROW,B_NODE_EXEC,"YCC",
1761 butr->xmin+3*sx,butr->ymin+60,sx,20,&node->custom1,1,4, 0, 0, "YCbCr Color Space");
1763 if (node->custom1==1) {
1764 c1="R"; c2="G"; c3="B";
1766 else if(node->custom1==2){
1767 c1="H"; c2="S"; c3="V";
1769 else if(node->custom1==3){
1770 c1="Y"; c2="U"; c3="V";
1772 else { // if(node->custom1==4){
1773 c1="Y"; c2="Cb"; c3="Cr";
1776 /*channel selector */
1777 uiDefButS(block, ROW, B_NODE_EXEC, c1,
1778 butr->xmin,butr->ymin+40,cx,20,&node->custom2,1, 1, 0, 0, "Channel 1");
1779 uiDefButS(block, ROW, B_NODE_EXEC, c2,
1780 butr->xmin+cx,butr->ymin+40,cx,20,&node->custom2,1, 2, 0, 0, "Channel 2");
1781 uiDefButS(block, ROW, B_NODE_EXEC, c3,
1782 butr->xmin+cx+cx,butr->ymin+40,cx,20,&node->custom2, 1, 3, 0, 0, "Channel 3");
1784 /*tolerance sliders */
1785 uiDefButF(block, NUMSLI, B_NODE_EXEC, "High ",
1786 butr->xmin, butr->ymin+20.0, butr->xmax-butr->xmin, 20,
1787 &c->t1, 0.0f, 1.0f, 100, 0, "Values higher than this setting are 100% opaque");
1788 uiDefButF(block, NUMSLI, B_NODE_EXEC, "Low ",
1789 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1790 &c->t2, 0.0f, 1.0f, 100, 0, "Values lower than this setting are 100% keyed");
1791 uiBlockEndAlign(block);
1793 /*keep t2 (low) less than t1 (high) */
1801 static int node_composit_buts_luma_matte(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1804 NodeChroma *c=node->storage;
1806 /*tolerance sliders */
1807 uiDefButF(block, NUMSLI, B_NODE_EXEC, "High ",
1808 butr->xmin, butr->ymin+20.0, butr->xmax-butr->xmin, 20,
1809 &c->t1, 0.0f, 1.0f, 100, 0, "Values higher than this setting are 100% opaque");
1810 uiDefButF(block, NUMSLI, B_NODE_EXEC, "Low ",
1811 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1812 &c->t2, 0.0f, 1.0f, 100, 0, "Values lower than this setting are 100% keyed");
1813 uiBlockEndAlign(block);
1815 /*keep t2 (low) less than t1 (high) */
1823 static int node_composit_buts_map_uv(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1826 uiDefButS(block, NUM, B_NODE_EXEC, "Alpha:",
1827 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1828 &node->custom1, 0, 100, 0, 0, "Conversion percentage of UV differences to Alpha");
1833 static int node_composit_buts_id_mask(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1836 uiDefButS(block, NUM, B_NODE_EXEC, "ID:",
1837 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1838 &node->custom1, 0, 10000, 0, 0, "Pass Index number to convert to Alpha");
1843 /* allocate sufficient! */
1844 static void node_imagetype_string(char *str)
1846 str += sprintf(str, "Save Image as: %%t|");
1847 str += sprintf(str, "Targa %%x%d|", R_TARGA);
1848 str += sprintf(str, "Targa Raw %%x%d|", R_RAWTGA);
1849 str += sprintf(str, "PNG %%x%d|", R_PNG);
1850 str += sprintf(str, "BMP %%x%d|", R_BMP);
1851 str += sprintf(str, "Jpeg %%x%d|", R_JPEG90);
1852 str += sprintf(str, "Iris %%x%d|", R_IRIS);
1853 str += sprintf(str, "Radiance HDR %%x%d|", R_RADHDR);
1854 str += sprintf(str, "Cineon %%x%d|", R_CINEON);
1855 str += sprintf(str, "DPX %%x%d|", R_DPX);
1856 str += sprintf(str, "OpenEXR %%x%d", R_OPENEXR);
1859 static void node_set_image_cb(bContext *C, void *ntree_v, void *node_v)
1861 bNodeTree *ntree= ntree_v;
1862 bNode *node= node_v;
1864 nodeSetActive(ntree, node);
1867 static int node_composit_buts_file_output(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1870 NodeImageFile *nif= node->storage;
1872 short x= (short)butr->xmin;
1873 short y= (short)butr->ymin;
1874 short w= (short)butr->xmax-butr->xmin;
1877 node_imagetype_string(str);
1879 uiBlockBeginAlign(block);
1881 bt = uiDefIconBut(block, BUT, B_NODE_SETIMAGE, ICON_FILESEL,
1883 0, 0, 0, 0, 0, "Open Fileselect to get Backbuf image");
1884 uiButSetFunc(bt, node_set_image_cb, ntree, node);
1886 uiDefBut(block, TEX, B_NOP, "",
1887 20+x, y+60, w-20, 20,
1888 nif->name, 0.0f, 240.0f, 0, 0, "");
1890 uiDefButS(block, MENU, B_NOP, str,
1892 &nif->imtype, 0.0f, 1.0f, 0, 0, "");
1894 if(nif->imtype==R_OPENEXR) {
1895 uiDefButBitS(block, TOG, R_OPENEXR_HALF, B_REDR, "Half",
1897 &nif->subimtype, 0, 0, 0, 0, "");
1899 uiDefButS(block, MENU,B_NOP, "Codec %t|None %x0|Pxr24 (lossy) %x1|ZIP (lossless) %x2|PIZ (lossless) %x3|RLE (lossless) %x4",
1900 x+w/2, y+20, w/2, 20,
1901 &nif->codec, 0, 0, 0, 0, "");
1904 uiDefButS(block, NUM, B_NOP, "Quality: ",
1906 &nif->quality, 10.0f, 100.0f, 10, 0, "");
1909 /* start frame, end frame */
1910 uiDefButI(block, NUM, B_NODE_EXEC, "SFra: ",
1912 &nif->sfra, 1, MAXFRAMEF, 10, 0, "");
1913 uiDefButI(block, NUM, B_NODE_EXEC, "EFra: ",
1915 &nif->efra, 1, MAXFRAMEF, 10, 0, "");
1921 static void node_scale_cb(bContext *C, void *node_v, void *unused_v)
1923 bNode *node= node_v;
1926 /* check the 2 inputs, and set them to reasonable values */
1927 for(nsock= node->inputs.first; nsock; nsock= nsock->next) {
1928 if(ELEM(node->custom1, CMP_SCALE_RELATIVE, CMP_SCALE_SCENEPERCENT))
1929 nsock->ns.vec[0]= 1.0;
1931 if(nsock->next==NULL)
1932 nsock->ns.vec[0]= (float)CTX_data_scene(C)->r.ysch;
1934 nsock->ns.vec[0]= (float)CTX_data_scene(C)->r.xsch;
1939 static int node_composit_buts_scale(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1942 uiBut *bt= uiDefButS(block, MENU, B_NODE_EXEC, "Relative %x0|Absolute %x1|Scene Size % %x2|",
1943 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1944 &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");
1945 uiButSetFunc(bt, node_scale_cb, node, NULL);
1950 static int node_composit_buts_invert(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1953 uiBlockBeginAlign(block);
1954 uiDefButBitS(block, TOG, CMP_CHAN_RGB, B_NODE_EXEC, "RGB",
1955 butr->xmin, butr->ymin, (butr->xmax-butr->xmin)/2, 20,
1956 &node->custom1, 0, 0, 0, 0, "");
1957 uiDefButBitS(block, TOG, CMP_CHAN_A, B_NODE_EXEC, "A",
1958 butr->xmin+(butr->xmax-butr->xmin)/2, butr->ymin, (butr->xmax-butr->xmin)/2, 20,
1959 &node->custom1, 0, 0, 0, 0, "");
1960 uiBlockEndAlign(block);
1965 static int node_composit_buts_premulkey(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
1971 bt=uiDefButS(block, MENU, B_NODE_EXEC, "Key to Premul %x0|Premul to Key %x1",
1972 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
1973 &node->custom1, 0, 0, 0, 0, "Conversion between premultiplied alpha and key alpha");
1978 /* only once called */
1979 static void node_composit_set_butfunc(bNodeType *ntype)
1981 switch(ntype->type) {
1982 /* case NODE_GROUP: note, typeinfo for group is generated... see "XXX ugly hack" */
1984 case CMP_NODE_IMAGE:
1985 ntype->butfunc= node_composit_buts_image;
1987 case CMP_NODE_R_LAYERS:
1988 ntype->butfunc= node_composit_buts_renderlayers;
1990 case CMP_NODE_NORMAL:
1991 ntype->butfunc= node_buts_normal;
1993 case CMP_NODE_CURVE_VEC:
1994 ntype->butfunc= node_buts_curvevec;
1996 case CMP_NODE_CURVE_RGB:
1997 ntype->butfunc= node_buts_curvecol;
1999 case CMP_NODE_VALUE:
2000 ntype->butfunc= node_buts_value;
2003 ntype->butfunc= node_buts_rgb;
2006 ntype->butfunc= node_composit_buts_flip;
2008 case CMP_NODE_SPLITVIEWER:
2009 ntype->butfunc= node_composit_buts_splitviewer;
2011 case CMP_NODE_MIX_RGB:
2012 ntype->butfunc= node_buts_mix_rgb;
2014 case CMP_NODE_VALTORGB:
2015 ntype->butfunc= node_buts_valtorgb;
2018 ntype->butfunc= node_composit_buts_crop;
2021 ntype->butfunc= node_composit_buts_blur;
2023 case CMP_NODE_DBLUR:
2024 ntype->butfunc= node_composit_buts_dblur;
2026 case CMP_NODE_BILATERALBLUR:
2027 ntype->butfunc= node_composit_buts_bilateralblur;
2029 /* qdn: defocus node */
2030 case CMP_NODE_DEFOCUS:
2031 ntype->butfunc = node_composit_buts_defocus;
2033 /* qdn: glare node */
2034 case CMP_NODE_GLARE:
2035 ntype->butfunc = node_composit_buts_glare;
2037 /* qdn: tonemap node */
2038 case CMP_NODE_TONEMAP:
2039 ntype->butfunc = node_composit_buts_tonemap;
2041 /* qdn: lens distortion node */
2042 case CMP_NODE_LENSDIST:
2043 ntype->butfunc = node_composit_buts_lensdist;
2045 case CMP_NODE_VECBLUR:
2046 ntype->butfunc= node_composit_buts_vecblur;
2048 case CMP_NODE_FILTER:
2049 ntype->butfunc= node_composit_buts_filter;
2051 case CMP_NODE_MAP_VALUE:
2052 ntype->butfunc= node_composit_buts_map_value;
2055 ntype->butfunc= node_buts_time;
2057 case CMP_NODE_ALPHAOVER:
2058 ntype->butfunc= node_composit_buts_alphaover;
2060 case CMP_NODE_HUE_SAT:
2061 ntype->butfunc= node_composit_buts_hue_sat;
2063 case CMP_NODE_TEXTURE:
2064 ntype->butfunc= node_buts_texture;
2066 case CMP_NODE_DILATEERODE:
2067 ntype->butfunc= node_composit_buts_dilateerode;
2069 case CMP_NODE_OUTPUT_FILE:
2070 ntype->butfunc= node_composit_buts_file_output;
2073 case CMP_NODE_DIFF_MATTE:
2074 ntype->butfunc=node_composit_buts_diff_matte;
2076 case CMP_NODE_COLOR_SPILL:
2077 ntype->butfunc=node_composit_buts_color_spill;
2079 case CMP_NODE_CHROMA:
2080 ntype->butfunc=node_composit_buts_chroma_matte;
2082 case CMP_NODE_SCALE:
2083 ntype->butfunc= node_composit_buts_scale;
2085 case CMP_NODE_CHANNEL_MATTE:
2086 ntype->butfunc= node_composit_buts_channel_matte;
2088 case CMP_NODE_LUMA_MATTE:
2089 ntype->butfunc= node_composit_buts_luma_matte;
2091 case CMP_NODE_MAP_UV:
2092 ntype->butfunc= node_composit_buts_map_uv;
2094 case CMP_NODE_ID_MASK:
2095 ntype->butfunc= node_composit_buts_id_mask;
2098 ntype->butfunc= node_buts_math;
2100 case CMP_NODE_INVERT:
2101 ntype->butfunc= node_composit_buts_invert;
2103 case CMP_NODE_PREMULKEY:
2104 ntype->butfunc= node_composit_buts_premulkey;
2107 ntype->butfunc= NULL;
2111 /* ****************** BUTTON CALLBACKS FOR TEXTURE NODES ***************** */
2113 static int node_texture_buts_bricks(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
2116 short w = butr->xmax-butr->xmin;
2119 uiBlockBeginAlign(block);
2123 block, NUM, B_NODE_EXEC, "Offset",
2124 butr->xmin, butr->ymin+20, w-ofw, 20,
2129 block, NUM, B_NODE_EXEC, "",
2130 butr->xmin+w-ofw, butr->ymin+20, ofw, 20,
2133 "Offset every N rows" );
2137 block, NUM, B_NODE_EXEC, "Squash",
2138 butr->xmin, butr->ymin+0, w-ofw, 20,
2143 block, NUM, B_NODE_EXEC, "",
2144 butr->xmin+w-ofw, butr->ymin+0, ofw, 20,
2147 "Stretch every N rows" );
2149 uiBlockEndAlign(block);
2154 /* Copied from buttons_shading.c -- needs unifying */
2155 static char* noisebasis_menu()
2157 static char nbmenu[256];
2158 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);
2162 static int node_texture_buts_proc(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
2164 Tex *tex = (Tex *)node->storage;
2176 switch( tex->type ) {
2179 uiBlockBeginAlign( block );
2180 uiDefButS( block, MENU, B_NODE_EXEC,
2181 "Linear %x0|Quad %x1|Ease %x2|Diag %x3|Sphere %x4|Halo %x5|Radial %x6",
2182 x, y+20, w, 20, &tex->stype, 0, 1, 0, 0, "Blend Type" );
2183 uiDefButBitS(block, TOG, TEX_FLIPBLEND, B_NODE_EXEC, "Flip XY", x, y, w, 20,
2184 &tex->flag, 0, 0, 0, 0, "Flips the direction of the progression 90 degrees");
2185 uiBlockEndAlign( block );
2192 uiBlockBeginAlign(block);
2194 uiDefButS(block, ROW, B_NODE_EXEC, "Soft", 0*w/3+x, 40+y, w/3, 18, &tex->stype, 2.0, (float)TEX_SOFT, 0, 0, "Uses soft marble");
2195 uiDefButS(block, ROW, B_NODE_EXEC, "Sharp", 1*w/3+x, 40+y, w/3, 18, &tex->stype, 2.0, (float)TEX_SHARP, 0, 0, "Uses more clearly defined marble");
2196 uiDefButS(block, ROW, B_NODE_EXEC, "Sharper", 2*w/3+x, 40+y, w/3, 18, &tex->stype, 2.0, (float)TEX_SHARPER, 0, 0, "Uses very clearly defined marble");
2198 uiDefButS(block, ROW, B_NODE_EXEC, "Soft noise", 0*w/2+x, 20+y, w/2, 19, &tex->noisetype, 12.0, (float)TEX_NOISESOFT, 0, 0, "Generates soft noise");
2199 uiDefButS(block, ROW, B_NODE_EXEC, "Hard noise", 1*w/2+x, 20+y, w/2, 19, &tex->noisetype, 12.0, (float)TEX_NOISEPERL, 0, 0, "Generates hard noise");
2201 uiDefButS(block, ROW, B_NODE_EXEC, "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.");
2202 uiDefButS(block, ROW, B_NODE_EXEC, "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");
2203 uiDefButS(block, ROW, B_NODE_EXEC, "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");
2205 uiBlockEndAlign(block);
2211 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");
2213 uiBlockBeginAlign(block);
2214 uiDefButS(block, ROW, B_TEXPRV, "Bands", x, 40+y, w/2, 18, &tex->stype, 2.0, (float)TEX_BANDNOISE, 0, 0, "Uses standard noise");
2215 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");
2217 uiDefButS(block, ROW, B_NODE_EXEC, "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.");
2218 uiDefButS(block, ROW, B_NODE_EXEC, "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");
2219 uiDefButS(block, ROW, B_NODE_EXEC, "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");
2221 uiDefButS(block, ROW, B_NODE_EXEC, "Soft noise", 0*w/2+x, 0+y, w/2, 19, &tex->noisetype, 12.0, (float)TEX_NOISESOFT, 0, 0, "Generates soft noise");
2222 uiDefButS(block, ROW, B_NODE_EXEC, "Hard noise", 1*w/2+x, 0+y, w/2, 19, &tex->noisetype, 12.0, (float)TEX_NOISEPERL, 0, 0, "Generates hard noise");
2223 uiBlockEndAlign(block);
2229 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");
2231 uiBlockBeginAlign(block);
2232 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");
2233 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");
2234 uiDefButS(block, ROW, B_TEXPRV, "Soft", x, y+20, w/2, 18, &tex->noisetype, 12.0, (float)TEX_NOISESOFT, 0, 0, "Generates soft noise");
2235 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");
2236 uiBlockEndAlign(block);
2238 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");
2244 uiBlockBeginAlign(block);
2245 uiDefButS(block, MENU, B_TEXPRV, noisebasis_menu(), x, y+18, w, 18, &tex->noisebasis2, 0,0,0,0, "Sets the noise basis to distort");
2246 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");
2247 uiBlockEndAlign(block);
2254 static int node_texture_buts_image(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
2260 uiBlockBeginAlign(block);
2263 IMAnames_to_pupstring(&strp, NULL, "LOAD NEW %x32767", &(G.main->image), NULL, NULL);
2265 bt= uiDefButS(block, MENU, B_NOP, strp,
2266 butr->xmin, butr->ymin, 19, 19,
2267 &node->menunr, 0, 0, 0, 0, "Browses existing choices");
2268 uiButSetFunc(bt, node_browse_image_cb, ntree, node);
2269 if(strp) MEM_freeN(strp);
2271 /* Add New button */
2272 if(node->id==NULL) {
2273 bt= uiDefBut(block, BUT, B_NODE_LOADIMAGE, "Load New",
2274 butr->xmin+19, butr->ymin, (short)(butr->xmax-butr->xmin-19.0f), 19,
2275 NULL, 0.0, 0.0, 0, 0, "Add new Image");
2276 uiButSetFunc(bt, node_active_cb, ntree, node);
2280 short xmin= (short)butr->xmin, xmax= (short)butr->xmax;
2281 short width= xmax - xmin - 19;
2283 bt= uiDefBut(block, TEX, B_NOP, "IM:",
2284 xmin+19, butr->ymin, width, 19,
2285 node->id->name+2, 0.0, 19.0, 0, 0, "Image name");
2286 uiButSetFunc(bt, node_ID_title_cb, node, NULL);
2292 static int node_texture_buts_output(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
2297 char *name = ((TexNodeOutput*)node->storage)->name;
2299 uiBlockBeginAlign(block);
2301 width = (short)(butr->xmax - butr->xmin);
2306 butr->xmin, butr->ymin,
2313 uiBlockEndAlign(block);
2318 /* only once called */
2319 static void node_texture_set_butfunc(bNodeType *ntype)
2321 if( ntype->type >= TEX_NODE_PROC && ntype->type < TEX_NODE_PROC_MAX ) {
2322 ntype->butfunc = node_texture_buts_proc;
2324 else switch(ntype->type) {
2327 ntype->butfunc = node_buts_math;
2330 case TEX_NODE_MIX_RGB:
2331 ntype->butfunc = node_buts_mix_rgb;
2334 case TEX_NODE_VALTORGB:
2335 ntype->butfunc = node_buts_valtorgb;
2338 case TEX_NODE_CURVE_RGB:
2339 ntype->butfunc= node_buts_curvecol;
2342 case TEX_NODE_CURVE_TIME:
2343 ntype->butfunc = node_buts_time;
2346 case TEX_NODE_TEXTURE:
2347 ntype->butfunc = node_buts_texture;
2350 case TEX_NODE_BRICKS:
2351 ntype->butfunc = node_texture_buts_bricks;
2354 case TEX_NODE_IMAGE:
2355 ntype->butfunc = node_texture_buts_image;
2358 case TEX_NODE_OUTPUT:
2359 ntype->butfunc = node_texture_buts_output;
2363 ntype->butfunc= NULL;
2367 /* ******* init draw callbacks for all tree types, only called in usiblender.c, once ************* */
2369 void ED_init_node_butfuncs(void)
2374 ntype= node_all_shaders.first;
2376 node_shader_set_butfunc(ntype);
2379 /* composit nodes */
2380 ntype= node_all_composit.first;
2382 node_composit_set_butfunc(ntype);
2385 ntype = node_all_textures.first;
2387 node_texture_set_butfunc(ntype);
2392 /* ************** Generic drawing ************** */
2395 void node_rename_but(char *s)
2398 ListBase listb={0, 0};
2399 int dy, x1, y1, sizex=80, sizey=30;
2400 short pivot[2], mval[2], ret=0;
2402 getmouseco_sc(mval);
2404 pivot[0]= CLAMPIS(mval[0], (sizex+10), G.curscreen->sizex-30);
2405 pivot[1]= CLAMPIS(mval[1], (sizey/2)+10, G.curscreen->sizey-(sizey/2)-10);
2407 if (pivot[0]!=mval[0] || pivot[1]!=mval[1])
2408 warp_pointer(pivot[0], pivot[1]);
2410 mywinset(G.curscreen->mainwin);
2412 x1= pivot[0]-sizex+10;
2413 y1= pivot[1]-sizey/2;
2416 block= uiNewBlock(&listb, "button", UI_EMBOSS, UI_HELV, G.curscreen->mainwin);
2417 uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT|UI_BLOCK_ENTER_OK);
2419 /* buttons have 0 as return event, to prevent menu to close on hotkeys */
2420 uiBlockBeginAlign(block);
2422 uiDefBut(block, TEX, B_NOP, "Name: ", (short)(x1),(short)(y1+dy), 150, 19, s, 0.0, 19.0, 0, 0, "Node user name");
2424 uiBlockEndAlign(block);
2426 uiDefBut(block, BUT, 32767, "OK", (short)(x1+150), (short)(y1+dy), 29, 19, NULL, 0, 0, 0, 0, "");
2428 uiBoundsBlock(block, 2);
2430 ret= uiDoBlocks(&listb, 0, 0);
2435 void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode)
2438 if((snode->flag & SNODE_BACKDRAW) && snode->treetype==NTREE_COMPOSIT) {
2439 Image *ima= BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
2440 ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
2446 /* somehow the offset has to be calculated inverse */
2448 glaDefine2DArea(&ar->winrct);
2449 /* ortho at pixel level curarea */
2450 wmOrtho2(-0.375, ar->winx-0.375, -0.375, ar->winy-0.375);
2452 x = (ar->winx-ibuf->x)/2 + snode->xof;
2453 y = (ar->winy-ibuf->y)/2 + snode->yof;
2456 glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
2457 else if(ibuf->channels==4)
2458 glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_FLOAT, ibuf->rect_float);
2466 /* note: needs to be userpref or opengl profile option */
2467 static void draw_nodespace_back_tex(ScrArea *sa, SpaceNode *snode)
2470 draw_nodespace_grid(snode);
2472 if(snode->flag & SNODE_BACKDRAW) {
2473 Image *ima= BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
2474 ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
2479 glMatrixMode(GL_PROJECTION);
2481 glMatrixMode(GL_MODELVIEW);
2484 glaDefine2DArea(&sa->winrct);
2486 if(ibuf->x > sa->winx || ibuf->y > sa->winy) {
2488 zoomx= (float)sa->winx/ibuf->x;
2489 zoomy= (float)sa->winy/ibuf->y;
2490 zoom = MIN2(zoomx, zoomy);
2493 x = (sa->winx-zoom*ibuf->x)/2 + snode->xof;
2494 y = (sa->winy-zoom*ibuf->y)/2 + snode->yof;
2496 glPixelZoom(zoom, zoom);
2498 glColor4f(1.0, 1.0, 1.0, 1.0);
2500 glaDrawPixelsTex(x, y, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
2501 else if(ibuf->channels==4)
2502 glaDrawPixelsTex(x, y, ibuf->x, ibuf->y, GL_FLOAT, ibuf->rect_float);
2504 glPixelZoom(1.0, 1.0);
2506 glMatrixMode(GL_PROJECTION);
2508 glMatrixMode(GL_MODELVIEW);
2515 /* if v2d not NULL, it clips and returns 0 if not visible */
2516 int node_link_bezier_points(View2D *v2d, SpaceNode *snode, bNodeLink *link, float coord_array[][2], int resol)
2518 float dist, vec[4][2];
2520 /* in v0 and v3 we put begin/end points */
2521 if(link->fromsock) {
2522 vec[0][0]= link->fromsock->locx;
2523 vec[0][1]= link->fromsock->locy;
2526 if(snode==NULL) return 0;
2527 vec[0][0]= snode->mx;
2528 vec[0][1]= snode->my;
2531 vec[3][0]= link->tosock->locx;
2532 vec[3][1]= link->tosock->locy;
2535 if(snode==NULL) return 0;
2536 vec[3][0]= snode->mx;
2537 vec[3][1]= snode->my;
2540 dist= 0.5f*ABS(vec[0][0] - vec[3][0]);
2542 /* check direction later, for top sockets */
2543 vec[1][0]= vec[0][0]+dist;
2544 vec[1][1]= vec[0][1];
2546 vec[2][0]= vec[3][0]-dist;
2547 vec[2][1]= vec[3][1];
2549 if(v2d && MIN4(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) > v2d->cur.xmax); /* clipped */
2550 else if (v2d && MAX4(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) < v2d->cur.xmin); /* clipped */
2553 /* always do all three, to prevent data hanging around */
2554 forward_diff_bezier(vec[0][0], vec[1][0], vec[2][0], vec[3][0], coord_array[0], resol, 2);
2555 forward_diff_bezier(vec[0][1], vec[1][1], vec[2][1], vec[3][1], coord_array[0]+1, resol, 2);
2562 #define LINK_RESOL 24
2563 void node_draw_link_bezier(View2D *v2d, SpaceNode *snode, bNodeLink *link, int th_col1, int th_col2, int do_shaded)
2565 float coord_array[LINK_RESOL+1][2];
2567 if(node_link_bezier_points(v2d, snode, link, coord_array, LINK_RESOL)) {
2568 float dist, spline_step = 0.0f;
2571 /* we can reuse the dist variable here to increment the GL curve eval amount*/
2572 dist = 1.0f/(float)LINK_RESOL;
2574 glBegin(GL_LINE_STRIP);
2575 for(i=0; i<=LINK_RESOL; i++) {
2577 UI_ThemeColorBlend(th_col1, th_col2, spline_step);
2578 spline_step += dist;
2580 glVertex2fv(coord_array[i]);
2586 /* note; this is used for fake links in groups too */
2587 void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link)
2589 int do_shaded= 1, th_col1= TH_WIRE, th_col2= TH_WIRE;
2591 if(link->fromnode==NULL && link->tonode==NULL)
2594 if(link->fromnode==NULL || link->tonode==NULL) {
2595 UI_ThemeColor(TH_WIRE);
2599 /* going to give issues once... */
2600 if(link->tosock->flag & SOCK_UNAVAIL)
2602 if(link->fromsock->flag & SOCK_UNAVAIL)
2605 /* a bit ugly... but thats how we detect the internal group links */
2606 if(link->fromnode==link->tonode) {
2607 UI_ThemeColorBlend(TH_BACK, TH_WIRE, 0.25f);
2612 if(link->fromnode->level >= link->tonode->level && link->tonode->level!=0xFFF) {
2613 if(link->fromnode->flag & SELECT)
2614 th_col1= TH_EDGE_SELECT;
2615 if(link->tonode->flag & SELECT)
2616 th_col2= TH_EDGE_SELECT;
2619 UI_ThemeColor(TH_REDALERT);
2625 node_draw_link_bezier(v2d, snode, link, th_col1, th_col2, do_shaded);
2630 static void nodes_panel_gpencil(short cntrl) // NODES_HANDLER_GREASEPENCIL
2635 snode= curarea->spacedata.first;
2637 block= uiNewBlock(&curarea->uiblocks, "nodes_panel_gpencil", UI_EMBOSS, UI_HELV, curarea->win);
2638 uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | cntrl);
2639 uiSetPanelHandler(NODES_HANDLER_GREASEPENCIL); // for close and esc
2640 if (uiNewPanel(curarea, block, "Grease Pencil", "SpaceNode", 100, 30, 318, 204)==0) return;
2642 /* we can only really draw stuff if there are nodes (otherwise no events are handled */
2643 if (snode->nodetree == NULL)
2646 /* allocate memory for gpd if drawing enabled (this must be done first or else we crash) */
2647 if (snode->flag & SNODE_DISPGP) {
2648 if (snode->gpd == NULL)
2649 gpencil_data_setactive(curarea, gpencil_data_addnew());
2652 if (snode->flag & SNODE_DISPGP) {
2653 bGPdata *gpd= snode->gpd;
2656 /* this is a variable height panel, newpanel doesnt force new size on existing panels */
2657 /* so first we make it default height */
2658 uiNewPanelHeight(block, 204);
2660 /* draw button for showing gpencil settings and drawings */
2661 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)");
2663 /* extend the panel if the contents won't fit */
2664 newheight= draw_gpencil_panel(block, gpd, curarea);
2665 uiNewPanelHeight(block, newheight);
2668 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");
2669 uiDefBut(block, LABEL, 1, " ", 160, 180, 150, 20, NULL, 0.0, 0.0, 0, 0, "");
2673 static void nodes_blockhandlers(ScrArea *sa)
2675 SpaceNode *snode= sa->spacedata.first;
2678 for(a=0; a<SPACE_MAXHANDLER; a+=2) {
2679 switch(snode->blockhandler[a]) {
2680 case NODES_HANDLER_GREASEPENCIL:
2681 nodes_panel_gpencil(snode->blockhandler[a+1]);
2685 /* clear action value for event */
2686 snode->blockhandler[a+1]= 0;
2688 uiDrawBlocksPanels(sa, 0);