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): none yet.
27 * ***** END GPL LICENSE BLOCK *****
34 #include "BLI_blenlib.h"
35 #include "BLI_arithb.h"
37 #include "DNA_action_types.h"
38 #include "DNA_ipo_types.h"
40 #include "DNA_material_types.h"
41 #include "DNA_node_types.h"
42 #include "DNA_object_types.h"
43 #include "DNA_scene_types.h"
44 #include "DNA_space_types.h"
45 #include "DNA_screen_types.h"
46 #include "DNA_texture_types.h"
47 #include "DNA_userdef_types.h"
49 #include "BKE_global.h"
50 #include "BKE_image.h"
51 #include "BKE_library.h"
53 #include "BKE_material.h"
55 #include "BKE_object.h"
56 #include "BKE_texture.h"
57 #include "BKE_utildefines.h"
60 #include "BIF_glutil.h"
61 #include "BIF_interface.h"
62 #include "BIF_interface_icons.h"
63 #include "BIF_language.h"
64 #include "BIF_mywindow.h"
65 #include "BIF_previewrender.h"
66 #include "BIF_resources.h"
67 #include "BIF_screen.h"
68 #include "BIF_space.h"
70 #include "BSE_drawipo.h"
78 #include "interface.h" /* urm... for rasterpos_safe, roundbox */
81 #include "MEM_guardedalloc.h"
83 static void snode_drawstring(SpaceNode *snode, char *str, int okwidth)
85 char drawstr[NODE_MAXSTR];
88 if(str[0]==0 || okwidth<4) return;
90 BLI_strncpy(drawstr, str, NODE_MAXSTR);
91 width= snode->aspect*BIF_GetStringWidth(snode->curfont, drawstr, 0);
94 int len= strlen(drawstr)-1;
96 while(width > okwidth && len>=0) {
99 width= snode->aspect*BIF_GetStringWidth(snode->curfont, drawstr, 0);
104 BIF_DrawString(snode->curfont, drawstr, 0);
108 /* ************** Socket callbacks *********** */
110 /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
111 static uiBlock *socket_vector_menu(void *butpoin_v)
113 float *butpoin= butpoin_v;
116 block= uiNewBlock(&curarea->uiblocks, "socket menu", UI_EMBOSS, UI_HELV, curarea->win);
118 /* use this for a fake extra empy space around the buttons */
119 uiDefBut(block, LABEL, 0, "", -4, -4, 188, 68, NULL, 0, 0, 0, 0, "");
121 uiBlockBeginAlign(block);
122 uiDefButF(block, NUMSLI, 0, "X ", 0,40,180,20, butpoin, -1.0, 1.0, 10, 0, "");
123 uiDefButF(block, NUMSLI, 0, "Y ", 0,20,180,20, butpoin+1, -1.0, 1.0, 10, 0, "");
124 uiDefButF(block, NUMSLI, 0, "Z ", 0,0,180,20, butpoin+2, -1.0, 1.0, 10, 0, "");
126 uiBlockSetDirection(block, UI_TOP);
128 allqueue(REDRAWNODE, 0);
133 static void node_sync_cb(void *snode_v, void *node_v)
135 SpaceNode *snode= snode_v;
137 if(snode->treetype==NTREE_SHADER) {
138 nodeShaderSynchronizeID(node_v, 1);
139 allqueue(REDRAWBUTSSHADING, 0);
143 /* ****************** GENERAL CALLBACKS FOR NODES ***************** */
145 static void node_ID_title_cb(void *node_v, void *unused_v)
150 test_idbutton(node->id->name+2); /* library.c, verifies unique name */
151 BLI_strncpy(node->name, node->id->name+2, 21);
153 allqueue(REDRAWBUTSSHADING, 0);
154 allqueue(REDRAWNODE, 0);
155 allqueue(REDRAWOOPS, 0);
160 static void node_but_title_cb(void *node_v, void *but_v)
164 BLI_strncpy(node->name, bt->drawstr, NODE_MAXSTR);
166 allqueue(REDRAWNODE, 0);
170 /* ****************** BUTTON CALLBACKS FOR ALL TREES ***************** */
172 static int node_buts_group(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
174 if(block && node->id) {
178 uiBlockBeginAlign(block);
181 width= (short)(butr->xmax-butr->xmin - (node->id->us>1?19.0f:0.0f));
182 bt= uiDefBut(block, TEX, B_NOP, "NT:",
183 butr->xmin, butr->ymin, width, 19,
184 node->id->name+2, 0.0, 19.0, 0, 0, "NodeTree name");
185 uiButSetFunc(bt, node_ID_title_cb, node, NULL);
190 sprintf(str1, "%d", node->id->us);
191 bt= uiDefBut(block, BUT, B_NOP, str1,
192 butr->xmax-19, butr->ymin, 19, 19,
193 NULL, 0, 0, 0, 0, "Displays number of users. Click to make a single-user copy.");
194 //uiButSetFunc(bt, node_mat_alone_cb, node, NULL);
197 uiBlockEndAlign(block);
202 static int node_buts_value(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
205 bNodeSocket *sock= node->outputs.first; /* first socket stores value */
207 uiDefButF(block, NUM, B_NODE_EXEC, "",
208 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
209 sock->ns.vec, 0.0f, 1.0f, 10, 2, "");
215 static int node_buts_rgb(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
218 bNodeSocket *sock= node->outputs.first; /* first socket stores value */
220 /* enforce square box drawing */
221 uiBlockSetEmboss(block, UI_EMBOSSP);
223 uiDefButF(block, HSVCUBE, B_NODE_EXEC, "",
224 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 12,
225 sock->ns.vec, 0.0f, 1.0f, 3, 0, "");
226 uiDefButF(block, HSVCUBE, B_NODE_EXEC, "",
227 butr->xmin, butr->ymin+15, butr->xmax-butr->xmin, butr->ymax-butr->ymin -15 -15,
228 sock->ns.vec, 0.0f, 1.0f, 2, 0, "");
229 uiDefButF(block, COL, B_NOP, "",
230 butr->xmin, butr->ymax-12, butr->xmax-butr->xmin, 12,
231 sock->ns.vec, 0.0, 0.0, -1, 0, "");
232 /* the -1 above prevents col button to popup a color picker */
234 uiBlockSetEmboss(block, UI_EMBOSS);
237 return 30 + (int)(node->width-NODE_DY);
240 static int node_buts_mix_rgb(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
246 bt=uiDefButS(block, MENU, B_NODE_EXEC, "Mix %x0|Add %x1|Subtract %x3|Multiply %x2|Screen %x4|Divide %x5|Difference %x6|Darken %x7|Lighten %x8",
247 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
248 &node->custom1, 0, 0, 0, 0, "");
249 uiButSetFunc(bt, node_but_title_cb, node, bt);
254 static int node_buts_valtorgb(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
258 draw_colorband_buts_small(block, node->storage, butr, B_NODE_EXEC);
264 static int node_buts_curvevec(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
267 curvemap_buttons(block, node->storage, 'v', B_NODE_EXEC, B_REDR, butr);
269 return (int)(node->width-NODE_DY);
272 static int node_buts_curvecol(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
275 curvemap_buttons(block, node->storage, 'c', B_NODE_EXEC, B_REDR, butr);
277 return (int)(node->width-NODE_DY);
280 static int node_buts_normal(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
283 bNodeSocket *sock= node->outputs.first; /* first socket stores normal */
285 uiDefButF(block, BUT_NORMAL, B_NODE_EXEC, "",
286 butr->xmin, butr->ymin, butr->xmax-butr->xmin, butr->ymax-butr->ymin,
287 sock->ns.vec, 0.0f, 1.0f, 0, 0, "");
290 return (int)(node->width-NODE_DY);
295 /* ****************** BUTTON CALLBACKS FOR SHADER NODES ***************** */
298 static void node_mat_alone_cb(void *node_v, void *unused)
302 node->id= (ID *)copy_material((Material *)node->id);
304 BIF_undo_push("Single user material");
305 allqueue(REDRAWBUTSSHADING, 0);
306 allqueue(REDRAWNODE, 0);
307 allqueue(REDRAWOOPS, 0);
310 static void node_browse_mat_cb(void *ntree_v, void *node_v)
312 bNodeTree *ntree= ntree_v;
315 if(node->menunr<1) return;
317 if(node->menunr==32767) { /* code for Add New */
319 /* make copy, but make sure it doesnt have the node tag nor nodes */
320 Material *ma= (Material *)node->id;
322 ma= copy_material(ma);
325 ntreeFreeTree(ma->nodetree);
326 MEM_freeN(ma->nodetree);
331 else node->id= (ID *)add_material("MatNode");
334 if(node->id) node->id->us--;
335 node->id= BLI_findlink(&G.main->mat, node->menunr-1);
336 id_us_plus(node->id);
338 BLI_strncpy(node->name, node->id->name+2, 21);
340 nodeSetActive(ntree, node);
342 allqueue(REDRAWBUTSSHADING, 0);
343 allqueue(REDRAWNODE, 0);
344 BIF_preview_changed(ID_MA);
349 static void node_new_mat_cb(void *ntree_v, void *node_v)
351 bNodeTree *ntree= ntree_v;
354 node->id= (ID *)add_material("MatNode");
355 BLI_strncpy(node->name, node->id->name+2, 21);
357 nodeSetActive(ntree, node);
359 allqueue(REDRAWBUTSSHADING, 0);
360 allqueue(REDRAWNODE, 0);
361 BIF_preview_changed(ID_MA);
365 static void node_texmap_cb(void *texmap_v, void *unused_v)
367 init_mapping(texmap_v);
370 static int node_shader_buts_material(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
374 short dx= (short)((butr->xmax-butr->xmin)/3.0f), has_us= (node->id && node->id->us>1);
375 short dy= (short)butr->ymin;
378 /* WATCH IT: we use this callback in material buttons, but then only want first row */
379 if(butr->ymax-butr->ymin > 21.0f) dy+= 19;
381 uiBlockBeginAlign(block);
382 if(node->id==NULL) uiBlockSetCol(block, TH_REDALERT);
383 else if(has_us) uiBlockSetCol(block, TH_BUT_SETTING1);
384 else uiBlockSetCol(block, TH_BUT_SETTING2);
387 IDnames_to_pupstring(&strp, NULL, "ADD NEW %x32767", &(G.main->mat), NULL, NULL);
389 bt= uiDefButS(block, MENU, B_NOP, strp,
390 butr->xmin, dy, 19, 19,
391 &node->menunr, 0, 0, 0, 0, "Browses existing choices or adds NEW");
392 uiButSetFunc(bt, node_browse_mat_cb, ntree, node);
393 if(strp) MEM_freeN(strp);
397 bt= uiDefBut(block, BUT, B_NOP, "Add New",
398 butr->xmin+19, dy, (short)(butr->xmax-butr->xmin-19.0f), 19,
399 NULL, 0.0, 0.0, 0, 0, "Add new Material");
400 uiButSetFunc(bt, node_new_mat_cb, ntree, node);
401 uiBlockSetCol(block, TH_AUTO);
405 short width= (short)(butr->xmax-butr->xmin-19.0f - (has_us?19.0f:0.0f));
406 bt= uiDefBut(block, TEX, B_NOP, "MA:",
407 butr->xmin+19, dy, width, 19,
408 node->id->name+2, 0.0, 19.0, 0, 0, "Material name");
409 uiButSetFunc(bt, node_ID_title_cb, node, NULL);
414 sprintf(str1, "%d", node->id->us);
415 bt= uiDefBut(block, BUT, B_NOP, str1,
416 butr->xmax-19, dy, 19, 19,
417 NULL, 0, 0, 0, 0, "Displays number of users. Click to make a single-user copy.");
418 uiButSetFunc(bt, node_mat_alone_cb, node, NULL);
421 /* WATCH IT: we use this callback in material buttons, but then only want first row */
422 if(butr->ymax-butr->ymin > 21.0f) {
424 uiBlockSetCol(block, TH_AUTO);
425 uiDefButBitS(block, TOG, SH_NODE_MAT_DIFF, B_NODE_EXEC, "Diff",
426 butr->xmin, butr->ymin, dx, 19,
427 &node->custom1, 0, 0, 0, 0, "Material Node outputs Diffuse");
428 uiDefButBitS(block, TOG, SH_NODE_MAT_SPEC, B_NODE_EXEC, "Spec",
429 butr->xmin+dx, butr->ymin, dx, 19,
430 &node->custom1, 0, 0, 0, 0, "Material Node outputs Specular");
431 uiDefButBitS(block, TOG, SH_NODE_MAT_NEG, B_NODE_EXEC, "Neg Normal",
432 butr->xmax-dx, butr->ymin, dx, 19,
433 &node->custom1, 0, 0, 0, 0, "Material Node uses inverted Normal");
436 uiBlockEndAlign(block);
441 static int node_shader_buts_texture(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
446 bt= uiDefIDPoinBut(block, test_texpoin_but, ID_TE, B_NODE_EXEC, "",
447 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 19,
449 uiButSetFunc(bt, node_ID_title_cb, node, NULL);
456 static int node_shader_buts_mapping(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
459 TexMapping *texmap= node->storage;
460 short dx= (short)((butr->xmax-butr->xmin)/7.0f);
461 short dy= (short)(butr->ymax-19);
463 uiBlockSetFunc(block, node_texmap_cb, texmap, NULL); /* all buttons get this */
465 uiBlockBeginAlign(block);
466 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+dx, dy, 2*dx, 19, texmap->loc, -1000.0f, 1000.0f, 10, 2, "");
467 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->loc+1, -1000.0f, 1000.0f, 10, 2, "");
468 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->loc+2, -1000.0f, 1000.0f, 10, 2, "");
470 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+dx, dy, 2*dx, 19, texmap->rot, -1000.0f, 1000.0f, 1000, 1, "");
471 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->rot+1, -1000.0f, 1000.0f, 1000, 1, "");
472 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->rot+2, -1000.0f, 1000.0f, 1000, 1, "");
474 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+dx, dy, 2*dx, 19, texmap->size, -1000.0f, 1000.0f, 10, 2, "");
475 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->size+1, -1000.0f, 1000.0f, 10, 2, "");
476 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->size+2, -1000.0f, 1000.0f, 10, 2, "");
478 uiBlockBeginAlign(block);
479 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+dx, dy, 2*dx, 19, texmap->min, -10.0f, 10.0f, 100, 2, "");
480 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->min+1, -10.0f, 10.0f, 100, 2, "");
481 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->min+2, -10.0f, 10.0f, 100, 2, "");
483 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+dx, dy, 2*dx, 19, texmap->max, -10.0f, 10.0f, 10, 2, "");
484 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->max+1, -10.0f, 10.0f, 10, 2, "");
485 uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->max+2, -10.0f, 10.0f, 10, 2, "");
486 uiBlockEndAlign(block);
490 dy= (short)(butr->ymax-19);
491 uiDefBut(block, LABEL, B_NOP, "Loc", butr->xmin, dy, dx, 19, NULL, 0.0f, 0.0f, 0, 0, "");
493 uiDefBut(block, LABEL, B_NOP, "Rot", butr->xmin, dy, dx, 19, NULL, 0.0f, 0.0f, 0, 0, "");
495 uiDefBut(block, LABEL, B_NOP, "Size", butr->xmin, dy, dx, 19, NULL, 0.0f, 0.0f, 0, 0, "");
497 uiDefButBitI(block, TOG, TEXMAP_CLIP_MIN, B_NODE_EXEC, "Min", butr->xmin, dy, dx-4, 19, &texmap->flag, 0.0f, 0.0f, 0, 0, "");
499 uiDefButBitI(block, TOG, TEXMAP_CLIP_MAX, B_NODE_EXEC, "Max", butr->xmin, dy, dx-4, 19, &texmap->flag, 0.0f, 0.0f, 0, 0, "");
506 /* only once called */
507 static void node_shader_set_butfunc(bNodeType *ntype)
509 switch(ntype->type) {
510 case NODE_GROUP: /* note, generic type, but put here because we call this function anyway */
511 ntype->butfunc= node_buts_group;
513 case SH_NODE_MATERIAL:
514 ntype->butfunc= node_shader_buts_material;
516 case SH_NODE_TEXTURE:
517 ntype->butfunc= node_shader_buts_texture;
520 ntype->butfunc= node_buts_normal;
522 case SH_NODE_CURVE_VEC:
523 ntype->butfunc= node_buts_curvevec;
525 case SH_NODE_CURVE_RGB:
526 ntype->butfunc= node_buts_curvecol;
528 case SH_NODE_MAPPING:
529 ntype->butfunc= node_shader_buts_mapping;
532 ntype->butfunc= node_buts_value;
535 ntype->butfunc= node_buts_rgb;
537 case SH_NODE_MIX_RGB:
538 ntype->butfunc= node_buts_mix_rgb;
540 case SH_NODE_VALTORGB:
541 ntype->butfunc= node_buts_valtorgb;
544 ntype->butfunc= NULL;
548 /* ****************** BUTTON CALLBACKS FOR COMPOSIT NODES ***************** */
552 static void node_browse_image_cb(void *ntree_v, void *node_v)
554 bNodeTree *ntree= ntree_v;
557 nodeSetActive(ntree, node);
559 if(node->menunr<1) return;
560 if(node->menunr==32767) { /* code for Load New */
561 addqueue(curarea->win, UI_BUT_EVENT, B_NODE_LOADIMAGE);
564 if(node->id) node->id->us--;
565 node->id= BLI_findlink(&G.main->image, node->menunr-1);
566 id_us_plus(node->id);
568 BLI_strncpy(node->name, node->id->name+2, 21);
570 addqueue(curarea->win, RENDERPREVIEW, 1);
575 static void node_active_cb(void *ntree_v, void *node_v)
577 nodeSetActive(ntree_v, node_v);
580 static int node_composit_buts_image(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
584 short dy= (short)butr->ymin;
587 uiBlockBeginAlign(block);
588 uiBlockSetCol(block, TH_BUT_SETTING2);
591 IDnames_to_pupstring(&strp, NULL, "LOAD NEW %x32767", &(G.main->image), NULL, NULL);
593 bt= uiDefButS(block, MENU, B_NOP, strp,
594 butr->xmin, dy, 19, 19,
595 &node->menunr, 0, 0, 0, 0, "Browses existing choices");
596 uiButSetFunc(bt, node_browse_image_cb, ntree, node);
597 if(strp) MEM_freeN(strp);
601 bt= uiDefBut(block, BUT, B_NODE_LOADIMAGE, "Load New",
602 butr->xmin+19, dy, (short)(butr->xmax-butr->xmin-19.0f), 19,
603 NULL, 0.0, 0.0, 0, 0, "Add new Image");
604 uiButSetFunc(bt, node_active_cb, ntree, node);
605 uiBlockSetCol(block, TH_AUTO);
609 short width= (short)(butr->xmax-butr->xmin-19.0f);
610 bt= uiDefBut(block, TEX, B_NOP, "IMA:",
611 butr->xmin+19, dy, width, 19,
612 node->id->name+2, 0.0, 19.0, 0, 0, "Image name");
613 uiButSetFunc(bt, node_ID_title_cb, node, NULL);
620 static int node_composit_buts_blur(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
625 uiBlockBeginAlign(block);
626 bt=uiDefButS(block, NUM, B_NODE_EXEC, "X:",
627 butr->xmin, butr->ymin, (butr->xmax-butr->xmin)/2, 19,
628 &node->custom1, 0, 256, 0, 0, "");
629 bt=uiDefButS(block, NUM, B_NODE_EXEC, "Y:",
630 butr->xmin+(butr->xmax-butr->xmin)/2, butr->ymin, (butr->xmax-butr->xmin)/2, 19,
631 &node->custom2, 0, 256, 0, 0, "");
636 static int node_composit_buts_filter(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
642 bt=uiDefButS(block, MENU, B_NODE_EXEC, "Soften %x0|Sharpen %x1|Laplace %x2|Sobel %x3|Prewitt %x4|Kirsch %x5|Shadow %x6",
643 butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20,
644 &node->custom1, 0, 0, 0, 0, "");
645 uiButSetFunc(bt, node_but_title_cb, node, bt);
651 /* only once called */
652 static void node_composit_set_butfunc(bNodeType *ntype)
654 switch(ntype->type) {
655 case NODE_GROUP: /* note, generic type, but put here because we call this function anyway */
656 ntype->butfunc= node_buts_group;
659 ntype->butfunc= node_composit_buts_image;
661 case CMP_NODE_NORMAL:
662 ntype->butfunc= node_buts_normal;
664 case CMP_NODE_CURVE_VEC:
665 ntype->butfunc= node_buts_curvevec;
667 case CMP_NODE_CURVE_RGB:
668 ntype->butfunc= node_buts_curvecol;
671 ntype->butfunc= node_buts_value;
674 ntype->butfunc= node_buts_rgb;
676 case CMP_NODE_MIX_RGB:
677 ntype->butfunc= node_buts_mix_rgb;
679 case CMP_NODE_VALTORGB:
680 ntype->butfunc= node_buts_valtorgb;
683 ntype->butfunc= node_composit_buts_blur;
685 case CMP_NODE_FILTER:
686 ntype->butfunc= node_composit_buts_filter;
689 ntype->butfunc= NULL;
694 /* ******* init draw callbacks for all tree types, only called in usiblender.c, once ************* */
696 void init_node_butfuncs(void)
698 bNodeType **typedefs;
701 typedefs= node_all_shaders; /* BKE_node.h */
703 node_shader_set_butfunc(*typedefs);
707 typedefs= node_all_composit; /* BKE_node.h */
709 node_composit_set_butfunc(*typedefs);
714 /* ************** Generic drawing ************** */
716 static void draw_nodespace_grid(SpaceNode *snode)
718 float start, step= 25.0f;
720 BIF_ThemeColorShade(TH_BACK, -10);
722 start= snode->v2d.cur.xmin -fmod(snode->v2d.cur.xmin, step);
725 for(; start<snode->v2d.cur.xmax; start+=step) {
726 glVertex2f(start, snode->v2d.cur.ymin);
727 glVertex2f(start, snode->v2d.cur.ymax);
730 start= snode->v2d.cur.ymin -fmod(snode->v2d.cur.ymin, step);
731 for(; start<snode->v2d.cur.ymax; start+=step) {
732 glVertex2f(snode->v2d.cur.xmin, start);
733 glVertex2f(snode->v2d.cur.xmax, start);
737 BIF_ThemeColorShade(TH_BACK, -18);
738 glVertex2f(0.0f, snode->v2d.cur.ymin);
739 glVertex2f(0.0f, snode->v2d.cur.ymax);
740 glVertex2f(snode->v2d.cur.xmin, 0.0f);
741 glVertex2f(snode->v2d.cur.xmax, 0.0f);
747 static void nodeshadow(rctf *rct, float radius, float aspect, int select)
755 if(radius > (rct->ymax-rct->ymin-10.0f)/2.0f)
756 rad= (rct->ymax-rct->ymin-10.0f)/2.0f;
760 if(select) a= 10.0f*aspect; else a= 7.0f*aspect;
761 for(; a>0.0f; a-=aspect) {
762 /* alpha ranges from 2 to 20 or so */
763 glColor4ub(0, 0, 0, alpha);
766 gl_round_box(GL_POLYGON, rct->xmin - a, rct->ymin - a, rct->xmax + a, rct->ymax-10.0f + a, rad+a);
769 /* outline emphasis */
770 glEnable( GL_LINE_SMOOTH );
771 glColor4ub(0, 0, 0, 100);
772 gl_round_box(GL_LINE_LOOP, rct->xmin-0.5f, rct->ymin-0.5f, rct->xmax+0.5f, rct->ymax+0.5f, radius);
773 glDisable( GL_LINE_SMOOTH );
778 /* nice AA filled circle */
779 static void socket_circle_draw(float x, float y, float size, int type, int select)
781 /* 16 values of sin function */
782 static float si[16] = {
783 0.00000000, 0.39435585,0.72479278,0.93775213,
784 0.99871650,0.89780453,0.65137248,0.29936312,
785 -0.10116832,-0.48530196,-0.79077573,-0.96807711,
786 -0.98846832,-0.84864425,-0.57126821,-0.20129852
788 /* 16 values of cos function */
789 static float co[16] ={
790 1.00000000,0.91895781,0.68896691,0.34730525,
791 -0.05064916,-0.44039415,-0.75875812,-0.95413925,
792 -0.99486932,-0.87434661,-0.61210598,-0.25065253,
793 0.15142777,0.52896401,0.82076344,0.97952994,
800 else if(type==SOCK_VALUE)
801 glColor3ub(160, 160, 160);
802 else if(type==SOCK_VECTOR)
803 glColor3ub(100, 100, 200);
804 else if(type==SOCK_RGBA)
805 glColor3ub(200, 200, 40);
807 glColor3ub(100, 200, 100);
811 glColor3ub(200, 200, 200);
812 else if(type==SOCK_VECTOR)
813 glColor3ub(140, 140, 240);
814 else if(type==SOCK_RGBA)
815 glColor3ub(240, 240, 100);
817 glColor3ub(140, 240, 140);
822 glVertex2f(x+size*si[a], y+size*co[a]);
825 glColor4ub(0, 0, 0, 150);
827 glEnable( GL_LINE_SMOOTH );
828 glBegin(GL_LINE_LOOP);
830 glVertex2f(x+size*si[a], y+size*co[a]);
832 glDisable( GL_LINE_SMOOTH );
837 static void node_draw_preview(bNodePreview *preview, rctf *prv)
839 float scale= (prv->xmax-prv->xmin)/((float)preview->xsize);
840 float centx= prv->xmin + 0.5*(prv->xmax-prv->xmin);
841 float centy= prv->ymin + 0.5*(prv->ymax-prv->ymin);
843 /* draw standard bacdrop to show alpha */
844 glBegin(GL_TRIANGLES);
845 glColor3f(0.625f, 0.625f, 0.625f);
846 glVertex2f(prv->xmin, prv->ymin);
847 glVertex2f(prv->xmax, prv->ymin);
848 glVertex2f(centx, centy);
849 glVertex2f(prv->xmin, prv->ymax);
850 glVertex2f(prv->xmax, prv->ymax);
851 glVertex2f(centx, centy);
853 glColor3f(0.25f, 0.25f, 0.25f);
854 glVertex2f(prv->xmin, prv->ymin);
855 glVertex2f(prv->xmin, prv->ymax);
856 glVertex2f(centx, centy);
857 glVertex2f(prv->xmax, prv->ymin);
858 glVertex2f(prv->xmax, prv->ymax);
859 glVertex2f(centx, centy);
862 glPixelZoom(scale, scale);
865 glaDrawPixelsTex(prv->xmin, prv->ymin, preview->xsize, preview->ysize, GL_FLOAT, preview->rect);
868 glPixelZoom(1.0f, 1.0f);
872 /* based on settings in node, sets drawing rect info. each redraw! */
873 static void node_update_hidden(bNode *node)
876 float rad, drad, hiddenrad= HIDDEN_RAD;
877 int totin=0, totout=0, tot;
879 /* calculate minimal radius */
880 for(nsock= node->inputs.first; nsock; nsock= nsock->next)
881 if(!(nsock->flag & SOCK_HIDDEN))
883 for(nsock= node->outputs.first; nsock; nsock= nsock->next)
884 if(!(nsock->flag & SOCK_HIDDEN))
887 tot= MAX2(totin, totout);
889 hiddenrad += 5.0*(float)(tot-4);
892 node->totr.xmin= node->locx;
893 node->totr.xmax= node->locx + 3*hiddenrad + node->miniwidth;
894 node->totr.ymax= node->locy + (hiddenrad - 0.5f*NODE_DY);
895 node->totr.ymin= node->totr.ymax - 2*hiddenrad;
898 rad=drad= M_PI/(1.0f + (float)totout);
900 for(nsock= node->outputs.first; nsock; nsock= nsock->next) {
901 if(!(nsock->flag & SOCK_HIDDEN)) {
902 nsock->locx= node->totr.xmax - hiddenrad + sin(rad)*hiddenrad;
903 nsock->locy= node->totr.ymin + hiddenrad + cos(rad)*hiddenrad;
909 rad=drad= - M_PI/(1.0f + (float)totin);
911 for(nsock= node->inputs.first; nsock; nsock= nsock->next) {
912 if(!(nsock->flag & SOCK_HIDDEN)) {
913 nsock->locx= node->totr.xmin + hiddenrad + sin(rad)*hiddenrad;
914 nsock->locy= node->totr.ymin + hiddenrad + cos(rad)*hiddenrad;
920 /* based on settings in node, sets drawing rect info. each redraw! */
921 static void node_update(bNode *node)
924 float dy= node->locy;
929 /* little bit space in top */
930 if(node->outputs.first)
934 for(nsock= node->outputs.first; nsock; nsock= nsock->next) {
935 if(!(nsock->flag & SOCK_HIDDEN)) {
936 nsock->locx= node->locx + node->width;
937 nsock->locy= dy - NODE_DYS;
942 node->prvr.xmin= node->butr.xmin= node->locx + NODE_DYS;
943 node->prvr.xmax= node->butr.xmax= node->locx + node->width- NODE_DYS;
946 if(node->flag & NODE_PREVIEW) {
949 if(node->preview && node->preview->xsize && node->preview->ysize)
950 aspect= (float)node->preview->ysize/(float)node->preview->xsize;
954 node->prvr.ymin= dy - aspect*(node->width-NODE_DY);
955 dy= node->prvr.ymin - NODE_DYS/2;
959 if((node->flag & NODE_OPTIONS) && node->typeinfo->butfunc) {
962 node->butr.ymin= dy - (float)node->typeinfo->butfunc(NULL, NULL, node, NULL);
963 dy= node->butr.ymin - NODE_DYS/2;
967 for(nsock= node->inputs.first; nsock; nsock= nsock->next) {
968 if(!(nsock->flag & SOCK_HIDDEN)) {
969 nsock->locx= node->locx;
970 nsock->locy= dy - NODE_DYS;
975 /* little bit space in end */
976 if(node->inputs.first || (node->flag & (NODE_OPTIONS|NODE_PREVIEW))==0 )
979 node->totr.xmin= node->locx;
980 node->totr.xmax= node->locx + node->width;
981 node->totr.ymax= node->locy;
985 /* based on settings in node, sets drawing rect info. each redraw! */
986 /* note: this assumes only 1 group at a time is drawn (linked data) */
987 /* in node->totr the entire boundbox for the group is stored */
988 static void node_update_group(bNode *gnode)
990 bNodeTree *ngroup= (bNodeTree *)gnode->id;
993 rctf *rect= &gnode->totr;
996 /* center them, is a bit of abuse of locx and locy though */
997 for(node= ngroup->nodes.first; node; node= node->next) {
998 node->locx+= gnode->locx;
999 node->locy+= gnode->locy;
1000 if(node->flag & NODE_HIDDEN)
1001 node_update_hidden(node);
1004 node->locx-= gnode->locx;
1005 node->locy-= gnode->locy;
1008 for(node= ngroup->nodes.first; node; node= node->next) {
1014 BLI_union_rctf(rect, &node->totr);
1016 if(counter==1) return; /* should be prevented? */
1018 rect->xmin-= NODE_DY;
1019 rect->ymin-= NODE_DY;
1020 rect->xmax+= NODE_DY;
1021 rect->ymax+= NODE_DY;
1023 /* output sockets */
1024 for(nsock= gnode->outputs.first; nsock; nsock= nsock->next) {
1025 nsock->locx= rect->xmax;
1026 nsock->locy= nsock->tosock->locy;
1030 for(nsock= gnode->inputs.first; nsock; nsock= nsock->next) {
1031 nsock->locx= rect->xmin;
1032 nsock->locy= nsock->tosock->locy;
1036 static void node_scaling_widget(int color_id, float aspect, float xmin, float ymin, float xmax, float ymax)
1041 dx= 0.5f*(xmax-xmin);
1042 dy= 0.5f*(ymax-ymin);
1044 BIF_ThemeColorShade(color_id, +30);
1045 fdrawline(xmin, ymin, xmax, ymax);
1046 fdrawline(xmin+dx, ymin, xmax, ymax-dy);
1048 BIF_ThemeColorShade(color_id, -10);
1049 fdrawline(xmin, ymin+aspect, xmax, ymax+aspect);
1050 fdrawline(xmin+dx, ymin+aspect, xmax, ymax-dy+aspect);
1053 static int node_get_colorid(bNode *node)
1055 if(node->typeinfo->nclass==NODE_CLASS_INPUT)
1056 return TH_NODE_IN_OUT;
1057 if(node->typeinfo->nclass==NODE_CLASS_OUTPUT) {
1058 if(node->flag & NODE_DO_OUTPUT)
1059 return TH_NODE_IN_OUT;
1063 if(node->typeinfo->nclass==NODE_CLASS_GENERATOR)
1064 return TH_NODE_GENERATOR;
1065 if(node->typeinfo->nclass==NODE_CLASS_OPERATOR)
1066 return TH_NODE_OPERATOR;
1067 if(node->typeinfo->nclass==NODE_CLASS_GROUP)
1068 return TH_NODE_GROUP;
1072 static void node_draw_basis(ScrArea *sa, SpaceNode *snode, bNode *node)
1076 rctf *rct= &node->totr;
1077 float slen, iconofs;
1078 int ofs, color_id= node_get_colorid(node);
1080 uiSetRoundBox(15-4);
1081 nodeshadow(rct, BASIS_RAD, snode->aspect, node->flag & SELECT);
1084 if(color_id==TH_NODE)
1085 BIF_ThemeColorShade(color_id, -20);
1087 BIF_ThemeColor(color_id);
1090 uiRoundBox(rct->xmin, rct->ymax-NODE_DY, rct->xmax, rct->ymax, BASIS_RAD);
1092 /* show/hide icons, note this sequence is copied in editnode.c */
1095 if(node->typeinfo->flag & NODE_PREVIEW) {
1098 if(node->flag & (NODE_ACTIVE_ID|NODE_DO_OUTPUT))
1099 icon_id= ICON_MATERIAL;
1101 icon_id= ICON_MATERIAL_DEHLT;
1104 BIF_icon_set_aspect(icon_id, snode->aspect);
1105 BIF_icon_draw_blended(iconofs, rct->ymax-NODE_DY+2, icon_id, 0, -60);
1106 glDisable(GL_BLEND);
1108 if(node->type == NODE_GROUP) {
1111 BIF_icon_set_aspect(ICON_NODE, snode->aspect);
1112 BIF_icon_draw_blended(iconofs, rct->ymax-NODE_DY+2, ICON_NODE, 0, -60);
1113 glDisable(GL_BLEND);
1115 if(node->typeinfo->flag & NODE_OPTIONS) {
1118 BIF_icon_set_aspect(ICON_BUTS, snode->aspect);
1119 BIF_icon_draw_blended(iconofs, rct->ymax-NODE_DY+2, ICON_BUTS, 0, -60);
1120 glDisable(GL_BLEND);
1122 if(node->outputs.first) {
1124 /* socket selector */
1126 if(node_has_hidden_sockets(node))
1131 BIF_icon_set_aspect(ICON_PLUS, snode->aspect);
1132 BIF_icon_draw_blended(iconofs, rct->ymax-NODE_DY+2, ICON_PLUS, 0, shade);
1133 glDisable(GL_BLEND);
1137 if(node->flag & SELECT)
1138 BIF_ThemeColor(TH_TEXT_HI);
1140 BIF_ThemeColorBlendShade(TH_TEXT, color_id, 0.4, 10);
1142 /* open/close entirely? */
1143 ui_draw_tria_icon(rct->xmin+8.0f, rct->ymax-NODE_DY+4.0f, snode->aspect, 'v');
1145 if(node->flag & SELECT)
1146 BIF_ThemeColor(TH_TEXT_HI);
1148 BIF_ThemeColor(TH_TEXT);
1150 ui_rasterpos_safe(rct->xmin+19.0f, rct->ymax-NODE_DY+5.0f, snode->aspect);
1151 snode_drawstring(snode, node->name, (int)(iconofs - rct->xmin-18.0f));
1154 BIF_ThemeColor(TH_NODE);
1156 uiRoundBox(rct->xmin, rct->ymin, rct->xmax, rct->ymax-NODE_DY, BASIS_RAD);
1158 /* scaling indicator */
1159 node_scaling_widget(TH_NODE, snode->aspect, rct->xmax-BASIS_RAD*snode->aspect, rct->ymin, rct->xmax, rct->ymin+BASIS_RAD*snode->aspect);
1161 /* outline active emphasis */
1162 if(node->flag & NODE_ACTIVE) {
1164 glColor4ub(200, 200, 200, 140);
1165 uiSetRoundBox(15-4);
1166 gl_round_box(GL_LINE_LOOP, rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD);
1167 glDisable(GL_BLEND);
1170 /* we make buttons for input sockets, if... */
1171 if(node->flag & NODE_OPTIONS) {
1172 if(node->inputs.first || node->typeinfo->butfunc) {
1173 uiBlock *block= uiNewBlock(NULL, "node buttons", UI_EMBOSS, UI_HELV, sa->win);
1174 BLI_addtail(&sa->uiblocks, block);
1175 uiBlockSetFlag(block, UI_BLOCK_NO_HILITE);
1177 uiSetButLock(snode->id->lib!=NULL, "Can't edit library data");
1182 /* hurmf... another candidate for callback, have to see how this works first */
1183 if(node->id && node->block && snode->treetype==NTREE_SHADER)
1184 nodeShaderSynchronizeID(node, 0);
1186 /* socket inputs, buttons */
1187 for(sock= node->inputs.first; sock; sock= sock->next) {
1188 if(!(sock->flag & SOCK_HIDDEN)) {
1189 socket_circle_draw(sock->locx, sock->locy, NODE_SOCKSIZE, sock->type, sock->flag & SELECT);
1191 if(node->block && sock->link==NULL) {
1192 float *butpoin= sock->ns.vec;
1194 if(node->type==NODE_GROUP && sock->tosock)
1195 butpoin= sock->tosock->ns.vec;
1197 if(sock->type==SOCK_VALUE) {
1198 bt= uiDefButF(node->block, NUM, B_NODE_EXEC, sock->name,
1199 (short)sock->locx+NODE_DYS, (short)(sock->locy)-9, (short)node->width-NODE_DY, 17,
1200 butpoin, 0.0f, 1.0f, 10, 2, "");
1201 uiButSetFunc(bt, node_sync_cb, snode, node);
1203 else if(sock->type==SOCK_VECTOR) {
1204 uiDefBlockBut(node->block, socket_vector_menu, butpoin, sock->name,
1205 (short)sock->locx+NODE_DYS, (short)sock->locy-9, (short)node->width-NODE_DY, 17,
1208 else if(node->block && sock->type==SOCK_RGBA) {
1209 short labelw= node->width-NODE_DY-40, width;
1211 if(labelw>0) width= 40; else width= node->width-NODE_DY;
1213 bt= uiDefButF(node->block, COL, B_NODE_EXEC, "",
1214 (short)(sock->locx+NODE_DYS), (short)sock->locy-8, width, 15,
1215 butpoin, 0, 0, 0, 0, "");
1216 uiButSetFunc(bt, node_sync_cb, snode, node);
1218 if(labelw>0) uiDefBut(node->block, LABEL, 0, sock->name,
1219 (short)(sock->locx+NODE_DYS) + 40, (short)sock->locy-8, labelw, 15,
1220 NULL, 0, 0, 0, 0, "");
1224 BIF_ThemeColor(TH_TEXT);
1225 ui_rasterpos_safe(sock->locx+8.0f, sock->locy-5.0f, snode->aspect);
1226 BIF_DrawString(snode->curfont, sock->name, 0);
1231 /* socket outputs */
1232 for(sock= node->outputs.first; sock; sock= sock->next) {
1233 if(!(sock->flag & SOCK_HIDDEN)) {
1234 socket_circle_draw(sock->locx, sock->locy, NODE_SOCKSIZE, sock->type, sock->flag & SELECT);
1236 BIF_ThemeColor(TH_TEXT);
1238 slen= snode->aspect*BIF_GetStringWidth(snode->curfont, sock->name, 0);
1239 while(slen > node->width) {
1241 slen= snode->aspect*BIF_GetStringWidth(snode->curfont, sock->name+ofs, 0);
1243 ui_rasterpos_safe(sock->locx-8.0f-slen, sock->locy-5.0f, snode->aspect);
1244 BIF_DrawString(snode->curfont, sock->name+ofs, 0);
1249 if(node->flag & NODE_PREVIEW)
1250 if(node->preview && node->preview->rect)
1251 node_draw_preview(node->preview, &node->prvr);
1254 if(node->flag & NODE_OPTIONS) {
1255 if(node->typeinfo->butfunc) {
1256 node->typeinfo->butfunc(node->block, snode->nodetree, node, &node->butr);
1258 uiDrawBlock(node->block);
1263 void node_draw_hidden(SpaceNode *snode, bNode *node)
1266 rctf *rct= &node->totr;
1267 float dx, centy= 0.5f*(rct->ymax+rct->ymin);
1268 float hiddenrad= 0.5f*(rct->ymax-rct->ymin);
1269 int color_id= node_get_colorid(node);
1273 nodeshadow(rct, hiddenrad, snode->aspect, node->flag & SELECT);
1276 BIF_ThemeColor(color_id);
1277 uiRoundBox(rct->xmin, rct->ymin, rct->xmax, rct->ymax, hiddenrad);
1279 /* outline active emphasis */
1280 if(node->flag & NODE_ACTIVE) {
1282 glColor4ub(200, 200, 200, 140);
1283 gl_round_box(GL_LINE_LOOP, rct->xmin, rct->ymin, rct->xmax, rct->ymax, hiddenrad);
1284 glDisable(GL_BLEND);
1288 if(node->flag & SELECT)
1289 BIF_ThemeColor(TH_TEXT_HI);
1291 BIF_ThemeColorBlendShade(TH_TEXT, color_id, 0.4, 10);
1293 /* open entirely icon */
1294 ui_draw_tria_icon(rct->xmin+9.0f, centy-6.0f, snode->aspect, 'h');
1296 if(node->flag & SELECT)
1297 BIF_ThemeColor(TH_TEXT_HI);
1299 BIF_ThemeColor(TH_TEXT);
1301 if(node->miniwidth>0.0f) {
1302 ui_rasterpos_safe(rct->xmin+21.0f, centy-4.0f, snode->aspect);
1303 snode_drawstring(snode, node->name, (int)(rct->xmax - rct->xmin-18.0f -12.0f));
1306 /* scale widget thing */
1307 BIF_ThemeColorShade(color_id, -10);
1309 fdrawline(rct->xmax-dx, centy-4.0f, rct->xmax-dx, centy+4.0f);
1310 fdrawline(rct->xmax-dx-3.0f*snode->aspect, centy-4.0f, rct->xmax-dx-3.0f*snode->aspect, centy+4.0f);
1312 BIF_ThemeColorShade(color_id, +30);
1314 fdrawline(rct->xmax-dx, centy-4.0f, rct->xmax-dx, centy+4.0f);
1315 fdrawline(rct->xmax-dx-3.0f*snode->aspect, centy-4.0f, rct->xmax-dx-3.0f*snode->aspect, centy+4.0f);
1318 for(sock= node->inputs.first; sock; sock= sock->next) {
1319 if(!(sock->flag & SOCK_HIDDEN))
1320 socket_circle_draw(sock->locx, sock->locy, NODE_SOCKSIZE, sock->type, sock->flag & SELECT);
1323 for(sock= node->outputs.first; sock; sock= sock->next) {
1324 if(!(sock->flag & SOCK_HIDDEN))
1325 socket_circle_draw(sock->locx, sock->locy, NODE_SOCKSIZE, sock->type, sock->flag & SELECT);
1329 /* note; this is used for fake links in groups too */
1330 void node_draw_link(SpaceNode *snode, bNodeLink *link)
1333 float dist, spline_step, mx=0.0f, my=0.0f;
1334 int curve_res, do_shaded= 1, th_col1= TH_WIRE, th_col2= TH_WIRE;
1336 if(link->fromnode==NULL && link->tonode==NULL)
1339 /* this is dragging link */
1340 if(link->fromnode==NULL || link->tonode==NULL) {
1342 getmouseco_areawin(mval);
1343 areamouseco_to_ipoco(G.v2d, mval, &mx, &my);
1344 BIF_ThemeColor(TH_WIRE);
1348 /* a bit ugly... but thats how we detect the internal group links */
1349 if(link->fromnode==link->tonode) {
1350 BIF_ThemeColorBlend(TH_BACK, TH_WIRE, 0.25f);
1355 if(link->fromnode->level >= link->tonode->level && link->tonode->level!=0xFFF) {
1356 if(link->fromnode->flag & SELECT)
1357 th_col1= TH_EDGE_SELECT;
1358 if(link->tonode->flag & SELECT)
1359 th_col2= TH_EDGE_SELECT;
1362 BIF_ThemeColor(TH_REDALERT);
1368 vec[0][2]= vec[1][2]= vec[2][2]= vec[3][2]= 0.0; /* only 2d spline, set the Z to 0*/
1370 /* in v0 and v3 we put begin/end points */
1371 if(link->fromnode) {
1372 vec[0][0]= link->fromsock->locx;
1373 vec[0][1]= link->fromsock->locy;
1380 vec[3][0]= link->tosock->locx;
1381 vec[3][1]= link->tosock->locy;
1388 dist= 0.5f*ABS(vec[0][0] - vec[3][0]);
1390 /* check direction later, for top sockets */
1391 vec[1][0]= vec[0][0]+dist;
1392 vec[1][1]= vec[0][1];
1394 vec[2][0]= vec[3][0]-dist;
1395 vec[2][1]= vec[3][1];
1397 if( MIN4(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) > G.v2d->cur.xmax); /* clipped */
1398 else if ( MAX4(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) < G.v2d->cur.xmin); /* clipped */
1402 /* we can reuse the dist variable here to increment the GL curve eval amount*/
1403 dist = 1.0f/curve_res;
1406 glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, vec[0]);
1407 glBegin(GL_LINE_STRIP);
1408 while (spline_step < 1.000001f) {
1410 BIF_ThemeColorBlend(th_col1, th_col2, spline_step);
1411 glEvalCoord1f(spline_step);
1412 spline_step += dist;
1418 static void node_draw_nodetree(ScrArea *sa, SpaceNode *snode, bNodeTree *ntree)
1423 if(ntree==NULL) return; /* groups... */
1427 glEnable( GL_LINE_SMOOTH );
1428 for(link= ntree->links.first; link; link= link->next)
1429 node_draw_link(snode, link);
1430 glDisable(GL_BLEND);
1431 glDisable( GL_LINE_SMOOTH );
1433 /* not selected first */
1434 for(node= ntree->nodes.first; node; node= node->next) {
1435 node->block= NULL; /* were freed */
1436 if(!(node->flag & SELECT)) {
1437 if(node->flag & NODE_GROUP_EDIT);
1438 else if(node->flag & NODE_HIDDEN)
1439 node_draw_hidden(snode, node);
1441 node_draw_basis(sa, snode, node);
1446 for(node= ntree->nodes.first; node; node= node->next) {
1447 if(node->flag & SELECT) {
1448 if(node->flag & NODE_GROUP_EDIT);
1449 else if(node->flag & NODE_HIDDEN)
1450 node_draw_hidden(snode, node);
1452 node_draw_basis(sa, snode, node);
1457 /* fake links from groupnode to internal nodes */
1458 static void node_draw_group_links(SpaceNode *snode, bNode *gnode)
1464 glEnable( GL_LINE_SMOOTH );
1466 fakelink.tonode= fakelink.fromnode= gnode;
1468 for(sock= gnode->inputs.first; sock; sock= sock->next) {
1469 if(!(sock->flag & SOCK_HIDDEN)) {
1471 fakelink.fromsock= sock;
1472 fakelink.tosock= sock->tosock;
1473 node_draw_link(snode, &fakelink);
1478 for(sock= gnode->outputs.first; sock; sock= sock->next) {
1479 if(!(sock->flag & SOCK_HIDDEN)) {
1481 fakelink.tosock= sock;
1482 fakelink.fromsock= sock->tosock;
1483 node_draw_link(snode, &fakelink);
1488 glDisable(GL_BLEND);
1489 glDisable( GL_LINE_SMOOTH );
1492 /* groups are, on creation, centered around 0,0 */
1493 static void node_draw_group(ScrArea *sa, SpaceNode *snode, bNode *gnode)
1495 bNodeTree *ngroup= (bNodeTree *)gnode->id;
1497 rctf rect= gnode->totr;
1499 /* backdrop header */
1502 BIF_ThemeColorShadeAlpha(TH_NODE_GROUP, 0, -70);
1503 gl_round_box(GL_POLYGON, rect.xmin, rect.ymax, rect.xmax, rect.ymax+NODE_DY, BASIS_RAD);
1506 BIF_ThemeColorShadeAlpha(TH_BACK, -8, -70);
1508 gl_round_box(GL_POLYGON, rect.xmin, rect.ymin, rect.xmax, rect.ymax, BASIS_RAD);
1510 /* selection outline */
1512 glColor4ub(200, 200, 200, 140);
1513 glEnable( GL_LINE_SMOOTH );
1514 gl_round_box(GL_LINE_LOOP, rect.xmin, rect.ymin, rect.xmax, rect.ymax+NODE_DY, BASIS_RAD);
1515 glDisable( GL_LINE_SMOOTH );
1516 glDisable(GL_BLEND);
1518 /* backdrop title */
1519 BIF_ThemeColor(TH_TEXT_HI);
1520 ui_rasterpos_safe(rect.xmin+8.0f, rect.ymax+5.0f, snode->aspect);
1521 BIF_DrawString(snode->curfont, ngroup->id.name+2, 0);
1523 /* links from groupsockets to the internal nodes */
1524 node_draw_group_links(snode, gnode);
1527 for(sock= gnode->inputs.first; sock; sock= sock->next)
1528 if(!(sock->flag & SOCK_HIDDEN))
1529 socket_circle_draw(sock->locx, sock->locy, NODE_SOCKSIZE, sock->type, sock->flag & SELECT);
1530 for(sock= gnode->outputs.first; sock; sock= sock->next)
1531 if(!(sock->flag & SOCK_HIDDEN))
1532 socket_circle_draw(sock->locx, sock->locy, NODE_SOCKSIZE, sock->type, sock->flag & SELECT);
1534 /* and finally the whole tree */
1535 node_draw_nodetree(sa, snode, ngroup);
1539 void drawnodespace(ScrArea *sa, void *spacedata)
1541 SpaceNode *snode= sa->spacedata.first;
1544 BIF_GetThemeColor3fv(TH_BACK, col);
1545 glClearColor(col[0], col[1], col[2], 0.0);
1546 glClear(GL_COLOR_BUFFER_BIT);
1548 calc_scrollrcts(sa, &(snode->v2d), sa->winx, sa->winy);
1550 myortho2(snode->v2d.cur.xmin, snode->v2d.cur.xmax, snode->v2d.cur.ymin, snode->v2d.cur.ymax);
1551 bwin_clear_viewmat(sa->win); /* clear buttons view */
1554 /* always free, blocks here have no unique identifier (1 block per node) */
1555 uiFreeBlocksWin(&sa->uiblocks, sa->win);
1558 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1559 glEnable(GL_MAP1_VERTEX_3);
1561 /* aspect+font, set each time */
1562 snode->aspect= (snode->v2d.cur.xmax - snode->v2d.cur.xmin)/((float)sa->winx);
1563 snode->curfont= uiSetCurFont_ext(snode->aspect);
1566 draw_nodespace_grid(snode);
1569 snode_set_context(snode);
1571 if(snode->nodetree) {
1574 /* for now, we set drawing coordinates on each redraw */
1575 for(node= snode->nodetree->nodes.first; node; node= node->next) {
1576 if(node->flag & NODE_GROUP_EDIT)
1577 node_update_group(node);
1578 else if(node->flag & NODE_HIDDEN)
1579 node_update_hidden(node);
1584 node_draw_nodetree(sa, snode, snode->nodetree);
1587 for(node= snode->nodetree->nodes.first; node; node= node->next) {
1588 if(node->flag & NODE_GROUP_EDIT)
1589 node_draw_group(sa, snode, node);
1593 /* restore viewport (not needed yet) */
1596 /* ortho at pixel level curarea */
1597 myortho2(-0.375, sa->winx-0.375, -0.375, sa->winy-0.375);
1599 draw_area_emboss(sa);
1600 curarea->win_swap= WIN_BACK_OK;
1602 /* in the end, this is a delayed previewrender test, to allow buttons to be first */
1603 if(snode->flag & SNODE_DO_PREVIEW) {
1604 addafterqueue(sa->win, RENDERPREVIEW, 1);
1605 snode->flag &= ~SNODE_DO_PREVIEW;