dd2dc0d796a9d85dc1009cf6eb131640478c5461
[blender.git] / source / blender / editors / space_node / node_draw.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
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. 
10  *
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.
15  *
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.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  * Contributor(s): Nathan Letwory
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <math.h>
30 #include <stdio.h>
31 #include <string.h>
32
33 #include "DNA_ID.h"
34 #include "DNA_node_types.h"
35 #include "DNA_image_types.h"
36 #include "DNA_material_types.h"
37 #include "DNA_mesh_types.h"
38 #include "DNA_action_types.h"
39 #include "DNA_color_types.h"
40 #include "DNA_customdata_types.h"
41 #include "DNA_gpencil_types.h"
42 #include "DNA_ipo_types.h"
43 #include "DNA_object_types.h"
44 #include "DNA_scene_types.h"
45 #include "DNA_space_types.h"
46 #include "DNA_screen_types.h"
47 #include "DNA_texture_types.h"
48 #include "DNA_text_types.h"
49 #include "DNA_userdef_types.h"
50
51 #include "BLI_arithb.h"
52 #include "BLI_blenlib.h"
53 #include "BLI_threads.h"
54 #include "MEM_guardedalloc.h"
55
56 #include "BKE_context.h"
57 #include "BKE_depsgraph.h"
58 #include "BKE_global.h"
59 #include "BKE_image.h"
60 #include "BKE_library.h"
61 #include "BKE_main.h"
62 #include "BKE_material.h"
63 #include "BKE_node.h"
64 #include "BKE_object.h"
65 #include "BKE_texture.h"
66 #include "BKE_text.h"
67 #include "BKE_utildefines.h"
68
69 /* #include "BDR_gpencil.h" XXX */
70
71 #include "BIF_gl.h"
72 #include "BIF_glutil.h"
73
74 #include "WM_api.h"
75 #include "WM_types.h"
76
77 #include "ED_screen.h"
78 #include "ED_util.h"
79 #include "ED_types.h"
80
81 #include "UI_interface.h"
82 #include "UI_interface_icons.h"
83 #include "UI_resources.h"
84 #include "UI_view2d.h"
85
86 #include "RNA_access.h"
87
88 #include "CMP_node.h"
89 #include "SHD_node.h"
90
91 #include "node_intern.h"
92
93 // XXX interface.h
94 extern void ui_dropshadow(rctf *rct, float radius, float aspect, int select);
95 extern void gl_round_box(int mode, float minx, float miny, float maxx, float maxy, float rad);
96 extern void ui_draw_tria_icon(float x, float y, float aspect, char dir);
97
98 void ED_node_changed_update(bContext *C, bNode *node)
99 {
100         SpaceNode *snode= CTX_wm_space_node(C);
101
102         if(!snode)
103                 return;
104
105         if(snode->treetype==NTREE_SHADER) {
106                 DAG_id_flush_update(snode->id, 0);
107                 WM_event_add_notifier(C, NC_MATERIAL|ND_SHADING, snode->id);
108         }
109         else if(snode->treetype==NTREE_COMPOSIT) {
110                 NodeTagChanged(snode->edittree, node);
111                 /* don't use NodeTagIDChanged, it gives far too many recomposites for image, scene layers, ... */
112                         
113                 /* not the best implementation of the world... but we need it to work now :) */
114                 if(node->type==CMP_NODE_R_LAYERS && node->custom2) {
115                         /* add event for this window (after render curarea can be changed) */
116                         //addqueue(curarea->win, UI_BUT_EVENT, B_NODE_TREE_EXEC);
117                         
118                         //composite_node_render(snode, node);
119                         //snode_handle_recalc(snode);
120                         
121                         /* add another event, a render can go fullscreen and open new window */
122                         //addqueue(curarea->win, UI_BUT_EVENT, B_NODE_TREE_EXEC);
123                 }
124                 else {
125                         node= node_tree_get_editgroup(snode->nodetree);
126                         if(node)
127                                 NodeTagIDChanged(snode->nodetree, node->id);
128                 }
129                 WM_event_add_notifier(C, NC_SCENE|ND_NODES, CTX_data_scene(C));
130         }                       
131         else if(snode->treetype==NTREE_TEXTURE) {
132                 DAG_id_flush_update(snode->id, 0);
133                 WM_event_add_notifier(C, NC_TEXTURE|ND_NODES, snode->id);
134         }
135
136 }
137
138 static void do_node_internal_buttons(bContext *C, void *node_v, int event)
139 {
140         if(event==B_NODE_EXEC)
141                 ED_node_changed_update(C, node_v);
142 }
143
144
145 static void node_scaling_widget(int color_id, float aspect, float xmin, float ymin, float xmax, float ymax)
146 {
147         float dx;
148         float dy;
149         
150         dx= 0.5f*(xmax-xmin);
151         dy= 0.5f*(ymax-ymin);
152         
153         UI_ThemeColorShade(color_id, +30);      
154         fdrawline(xmin, ymin, xmax, ymax);
155         fdrawline(xmin+dx, ymin, xmax, ymax-dy);
156         
157         UI_ThemeColorShade(color_id, -10);
158         fdrawline(xmin, ymin+aspect, xmax, ymax+aspect);
159         fdrawline(xmin+dx, ymin+aspect, xmax, ymax-dy+aspect);
160 }
161
162 /* based on settings in node, sets drawing rect info. each redraw! */
163 static void node_update(const bContext *C, bNodeTree *ntree, bNode *node)
164 {
165         uiLayout *layout;
166         PointerRNA ptr;
167         bNodeSocket *nsock;
168         float dy= node->locy;
169         int buty;
170         char str[32];
171         
172         /* header */
173         dy-= NODE_DY;
174         
175         /* little bit space in top */
176         if(node->outputs.first)
177                 dy-= NODE_DYS/2;
178
179         /* output sockets */
180         for(nsock= node->outputs.first; nsock; nsock= nsock->next) {
181                 if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) {
182                         nsock->locx= node->locx + node->width;
183                         nsock->locy= dy - NODE_DYS;
184                         dy-= NODE_DY;
185                 }
186         }
187
188         node->prvr.xmin= node->locx + NODE_DYS;
189         node->prvr.xmax= node->locx + node->width- NODE_DYS;
190         
191         /* preview rect? */
192         if(node->flag & NODE_PREVIEW) {
193                 /* only recalculate size when there's a preview actually, otherwise we use stored result */
194                 BLI_lock_thread(LOCK_PREVIEW);
195
196                 if(node->preview && node->preview->rect) {
197                         float aspect= 1.0f;
198                         
199                         if(node->preview && node->preview->xsize && node->preview->ysize) 
200                                 aspect= (float)node->preview->ysize/(float)node->preview->xsize;
201                         
202                         dy-= NODE_DYS/2;
203                         node->prvr.ymax= dy;
204                         
205                         if(aspect <= 1.0f)
206                                 node->prvr.ymin= dy - aspect*(node->width-NODE_DY);
207                         else {
208                                 float dx= (node->width - NODE_DYS) - (node->width- NODE_DYS)/aspect;    /* width correction of image */
209                                 
210                                 node->prvr.ymin= dy - (node->width-NODE_DY);
211                                 
212                                 node->prvr.xmin+= 0.5f*dx;
213                                 node->prvr.xmax-= 0.5f*dx;
214                         }
215
216                         dy= node->prvr.ymin - NODE_DYS/2;
217
218                         /* make sure that maximums are bigger or equal to minimums */
219                         if(node->prvr.xmax < node->prvr.xmin) SWAP(float, node->prvr.xmax, node->prvr.xmin);
220                         if(node->prvr.ymax < node->prvr.ymin) SWAP(float, node->prvr.ymax, node->prvr.ymin);
221                 }
222                 else {
223                         float oldh= node->prvr.ymax - node->prvr.ymin;
224                         if(oldh==0.0f)
225                                 oldh= 0.6f*node->width-NODE_DY;
226                         dy-= NODE_DYS/2;
227                         node->prvr.ymax= dy;
228                         node->prvr.ymin= dy - oldh;
229                         dy= node->prvr.ymin - NODE_DYS/2;
230                 }
231
232                 BLI_unlock_thread(LOCK_PREVIEW);
233         }
234
235         /* XXX ugly hack, typeinfo for group is generated */
236         if(node->type == NODE_GROUP)
237                 ; // XXX node->typeinfo->uifunc= node_buts_group;
238
239         /* ui block */
240         sprintf(str, "node buttons %p", node);
241         node->block= uiBeginBlock(C, CTX_wm_region(C), str, UI_EMBOSS);
242         uiBlockSetHandleFunc(node->block, do_node_internal_buttons, node);
243         
244         /* buttons rect? */
245         if((node->flag & NODE_OPTIONS) && node->typeinfo->uifunc) {
246                 dy-= NODE_DYS/2;
247
248                 /* set this for uifunc() that don't use layout engine yet */
249                 node->butr.xmin= 0;
250                 node->butr.xmax= node->width - 2*NODE_DYS;
251                 node->butr.ymin= 0;
252                 node->butr.ymax= 0;
253
254                 RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr);
255
256                 layout= uiBlockLayout(node->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL,
257                         node->locx+NODE_DYS, dy, node->butr.xmax, 20, U.uistyles.first);
258
259                 node->typeinfo->uifunc(layout, &ptr);
260                 uiBlockEndAlign(node->block);
261                 uiBlockLayoutResolve(node->block, NULL, &buty);
262
263                 dy= buty - NODE_DYS/2;
264         }
265
266         /* input sockets */
267         for(nsock= node->inputs.first; nsock; nsock= nsock->next) {
268                 if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) {
269                         nsock->locx= node->locx;
270                         nsock->locy= dy - NODE_DYS;
271                         dy-= NODE_DY;
272                 }
273         }
274         
275         /* little bit space in end */
276         if(node->inputs.first || (node->flag & (NODE_OPTIONS|NODE_PREVIEW))==0 )
277                 dy-= NODE_DYS/2;
278
279         node->totr.xmin= node->locx;
280         node->totr.xmax= node->locx + node->width;
281         node->totr.ymax= node->locy;
282         node->totr.ymin= dy;
283 }
284
285 /* based on settings in node, sets drawing rect info. each redraw! */
286 static void node_update_hidden(const bContext *C, bNode *node)
287 {
288         bNodeSocket *nsock;
289         float rad, drad, hiddenrad= HIDDEN_RAD;
290         int totin=0, totout=0, tot;
291         char str[32];
292         
293         /* calculate minimal radius */
294         for(nsock= node->inputs.first; nsock; nsock= nsock->next)
295                 if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)))
296                         totin++;
297         for(nsock= node->outputs.first; nsock; nsock= nsock->next)
298                 if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)))
299                         totout++;
300         
301         tot= MAX2(totin, totout);
302         if(tot>4) {
303                 hiddenrad += 5.0f*(float)(tot-4);
304         }
305         
306         node->totr.xmin= node->locx;
307         node->totr.xmax= node->locx + 3*hiddenrad + node->miniwidth;
308         node->totr.ymax= node->locy + (hiddenrad - 0.5f*NODE_DY);
309         node->totr.ymin= node->totr.ymax - 2*hiddenrad;
310         
311         /* output sockets */
312         rad=drad= (float)M_PI/(1.0f + (float)totout);
313         
314         for(nsock= node->outputs.first; nsock; nsock= nsock->next) {
315                 if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) {
316                         nsock->locx= node->totr.xmax - hiddenrad + (float)sin(rad)*hiddenrad;
317                         nsock->locy= node->totr.ymin + hiddenrad + (float)cos(rad)*hiddenrad;
318                         rad+= drad;
319                 }
320         }
321         
322         /* input sockets */
323         rad=drad= - (float)M_PI/(1.0f + (float)totin);
324         
325         for(nsock= node->inputs.first; nsock; nsock= nsock->next) {
326                 if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) {
327                         nsock->locx= node->totr.xmin + hiddenrad + (float)sin(rad)*hiddenrad;
328                         nsock->locy= node->totr.ymin + hiddenrad + (float)cos(rad)*hiddenrad;
329                         rad+= drad;
330                 }
331         }
332
333         /* ui block */
334         sprintf(str, "node buttons %p", node);
335         node->block= uiBeginBlock(C, CTX_wm_region(C), str, UI_EMBOSS);
336         uiBlockSetHandleFunc(node->block, do_node_internal_buttons, node);
337 }
338
339 static int node_get_colorid(bNode *node)
340 {
341         if(node->typeinfo->nclass==NODE_CLASS_INPUT)
342                 return TH_NODE_IN_OUT;
343         if(node->typeinfo->nclass==NODE_CLASS_OUTPUT) {
344                 if(node->flag & NODE_DO_OUTPUT)
345                         return TH_NODE_IN_OUT;
346                 else
347                         return TH_NODE;
348         }
349         if(node->typeinfo->nclass==NODE_CLASS_CONVERTOR)
350                 return TH_NODE_CONVERTOR;
351         if(ELEM3(node->typeinfo->nclass, NODE_CLASS_OP_COLOR, NODE_CLASS_OP_VECTOR, NODE_CLASS_OP_FILTER))
352                 return TH_NODE_OPERATOR;
353         if(node->typeinfo->nclass==NODE_CLASS_GROUP)
354                 return TH_NODE_GROUP;
355         return TH_NODE;
356 }
357
358 /* based on settings in node, sets drawing rect info. each redraw! */
359 /* note: this assumes only 1 group at a time is drawn (linked data) */
360 /* in node->totr the entire boundbox for the group is stored */
361 static void node_update_group(const bContext *C, bNodeTree *ntree, bNode *gnode)
362 {
363         bNodeTree *ngroup= (bNodeTree *)gnode->id;
364         bNode *node;
365         bNodeSocket *nsock;
366         rctf *rect= &gnode->totr;
367         int counter;
368         
369         /* center them, is a bit of abuse of locx and locy though */
370         for(node= ngroup->nodes.first; node; node= node->next) {
371                 node->locx+= gnode->locx;
372                 node->locy+= gnode->locy;
373                 if(node->flag & NODE_HIDDEN)
374                         node_update_hidden(C, node);
375                 else
376                         node_update(C, ntree, node);
377                 node->locx-= gnode->locx;
378                 node->locy-= gnode->locy;
379         }
380         counter= 1;
381         for(node= ngroup->nodes.first; node; node= node->next) {
382                 if(counter) {
383                         *rect= node->totr;
384                         counter= 0;
385                 }
386                 else
387                         BLI_union_rctf(rect, &node->totr);
388         }
389         if(counter==1) return;  /* should be prevented? */
390         
391         rect->xmin-= NODE_DY;
392         rect->ymin-= NODE_DY;
393         rect->xmax+= NODE_DY;
394         rect->ymax+= NODE_DY;
395         
396         /* output sockets */
397         for(nsock= gnode->outputs.first; nsock; nsock= nsock->next) {
398                 nsock->locx= rect->xmax;
399                 nsock->locy= nsock->tosock->locy;
400         }
401         
402         /* input sockets */
403         for(nsock= gnode->inputs.first; nsock; nsock= nsock->next) {
404                 nsock->locx= rect->xmin;
405                 nsock->locy= nsock->tosock->locy;
406         }
407 }
408
409 /* note: in cmp_util.c is similar code, for node_compo_pass_on() */
410 static void node_draw_mute_line(View2D *v2d, SpaceNode *snode, bNode *node)
411 {
412         bNodeSocket *valsock= NULL, *colsock= NULL, *vecsock= NULL;
413         bNodeSocket *sock;
414         bNodeLink link;
415         int a;
416         
417         memset(&link, 0, sizeof(bNodeLink));
418         
419         /* connect the first value buffer in with first value out */
420         /* connect the first RGBA buffer in with first RGBA out */
421         
422         /* test the inputs */
423         for(a=0, sock= node->inputs.first; sock; sock= sock->next, a++) {
424                 if(nodeCountSocketLinks(snode->edittree, sock)) {
425                         if(sock->type==SOCK_VALUE && valsock==NULL) valsock= sock;
426                         if(sock->type==SOCK_VECTOR && vecsock==NULL) vecsock= sock;
427                         if(sock->type==SOCK_RGBA && colsock==NULL) colsock= sock;
428                 }
429         }
430         
431         /* outputs, draw lines */
432         UI_ThemeColor(TH_REDALERT);
433         glEnable(GL_BLEND);
434         glEnable( GL_LINE_SMOOTH );
435         
436         if(valsock || colsock || vecsock) {
437                 for(a=0, sock= node->outputs.first; sock; sock= sock->next, a++) {
438                         if(nodeCountSocketLinks(snode->edittree, sock)) {
439                                 link.tosock= sock;
440                                 
441                                 if(sock->type==SOCK_VALUE && valsock) {
442                                         link.fromsock= valsock;
443                                         node_draw_link_bezier(v2d, snode, &link, TH_WIRE, TH_WIRE, 0);
444                                         valsock= NULL;
445                                 }
446                                 if(sock->type==SOCK_VECTOR && vecsock) {
447                                         link.fromsock= vecsock;
448                                         node_draw_link_bezier(v2d, snode, &link, TH_WIRE, TH_WIRE, 0);
449                                         vecsock= NULL;
450                                 }
451                                 if(sock->type==SOCK_RGBA && colsock) {
452                                         link.fromsock= colsock;
453                                         node_draw_link_bezier(v2d, snode, &link, TH_WIRE, TH_WIRE, 0);
454                                         colsock= NULL;
455                                 }
456                         }
457                 }
458         }
459         glDisable(GL_BLEND);
460         glDisable( GL_LINE_SMOOTH );
461 }
462
463 /* nice AA filled circle */
464 /* this might have some more generic use */
465 static void circle_draw(float x, float y, float size, int type, int col[3])
466 {
467         /* 16 values of sin function */
468         static float si[16] = {
469                 0.00000000f, 0.39435585f,0.72479278f,0.93775213f,
470                 0.99871650f,0.89780453f,0.65137248f,0.29936312f,
471                 -0.10116832f,-0.48530196f,-0.79077573f,-0.96807711f,
472                 -0.98846832f,-0.84864425f,-0.57126821f,-0.20129852f
473         };
474         /* 16 values of cos function */
475         static float co[16] ={
476                 1.00000000f,0.91895781f,0.68896691f,0.34730525f,
477                 -0.05064916f,-0.44039415f,-0.75875812f,-0.95413925f,
478                 -0.99486932f,-0.87434661f,-0.61210598f,-0.25065253f,
479                 0.15142777f,0.52896401f,0.82076344f,0.97952994f,
480         };
481         int a;
482         
483         glColor3ub(col[0], col[1], col[2]);
484         
485         glBegin(GL_POLYGON);
486         for(a=0; a<16; a++)
487                 glVertex2f(x+size*si[a], y+size*co[a]);
488         glEnd();
489         
490         glColor4ub(0, 0, 0, 150);
491         glEnable(GL_BLEND);
492         glEnable( GL_LINE_SMOOTH );
493         glBegin(GL_LINE_LOOP);
494         for(a=0; a<16; a++)
495                 glVertex2f(x+size*si[a], y+size*co[a]);
496         glEnd();
497         glDisable( GL_LINE_SMOOTH );
498         glDisable(GL_BLEND);
499 }
500
501 static void socket_circle_draw(bNodeSocket *sock, float size)
502 {
503         int col[3];
504         
505         /* choose color based on sock flags */
506         if(sock->flag & SELECT) {
507                 if(sock->flag & SOCK_SEL) {
508                         col[0]= 240; col[1]= 200; col[2]= 40;}
509                 else if(sock->type==SOCK_VALUE) {
510                         col[0]= 200; col[1]= 200; col[2]= 200;}
511                 else if(sock->type==SOCK_VECTOR) {
512                         col[0]= 140; col[1]= 140; col[2]= 240;}
513                 else if(sock->type==SOCK_RGBA) {
514                         col[0]= 240; col[1]= 240; col[2]= 100;}
515                 else {
516                         col[0]= 140; col[1]= 240; col[2]= 140;}
517         }
518         else if(sock->flag & SOCK_SEL) {
519                 col[0]= 200; col[1]= 160; col[2]= 0;}
520         else {
521                 if(sock->type==-1) {
522                         col[0]= 0; col[1]= 0; col[2]= 0;}
523                 else if(sock->type==SOCK_VALUE) {
524                         col[0]= 160; col[1]= 160; col[2]= 160;}
525                 else if(sock->type==SOCK_VECTOR) {
526                         col[0]= 100; col[1]= 100; col[2]= 200;}
527                 else if(sock->type==SOCK_RGBA) {
528                         col[0]= 200; col[1]= 200; col[2]= 40;}
529                 else { 
530                         col[0]= 100; col[1]= 200; col[2]= 100;}
531         }
532         
533         circle_draw(sock->locx, sock->locy, size, sock->type, col);
534 }
535
536 static void node_sync_cb(bContext *C, void *snode_v, void *node_v)
537 {
538         SpaceNode *snode= snode_v;
539         
540         if(snode->treetype==NTREE_SHADER) {
541                 nodeShaderSynchronizeID(node_v, 1);
542                 // allqueue(REDRAWBUTSSHADING, 0);
543         }
544 }
545
546 /* **************  Socket callbacks *********** */
547
548 static void socket_vector_menu_cb(bContext *C, void *node_v, void *ntree_v)
549 {
550         if(node_v && ntree_v) {
551                 NodeTagChanged(ntree_v, node_v); 
552                 // addqueue(curarea->win, UI_BUT_EVENT, B_NODE_EXEC); XXX
553         }
554 }
555
556 /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
557 static uiBlock *socket_vector_menu(bContext *C, ARegion *ar, void *socket_v)
558 {
559         SpaceNode *snode= CTX_wm_space_node(C);
560         ScrArea *sa= CTX_wm_area(C);
561         bNode *node;
562         bNodeSocket *sock= socket_v;
563         bNodeStack *ns= &sock->ns;
564         uiBlock *block;
565         uiBut *bt;
566         
567         /* a bit ugly... retrieve the node the socket comes from */
568         for(node= snode->nodetree->nodes.first; node; node= node->next) {
569                 bNodeSocket *sockt;
570                 for(sockt= node->inputs.first; sockt; sockt= sockt->next)
571                         if(sockt==sock)
572                                 break;
573                 if(sockt)
574                         break;
575         }
576         
577         block= uiBeginBlock(C, ar, "socket menu", UI_EMBOSS);
578         uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN);
579
580         /* use this for a fake extra empy space around the buttons */
581         uiDefBut(block, LABEL, 0, "",                   -4, -4, 188, 68, NULL, 0, 0, 0, 0, "");
582         
583         uiBlockBeginAlign(block);
584         bt= uiDefButF(block, NUMSLI, 0, "X ",    0,40,180,20, ns->vec, ns->min, ns->max, 10, 0, "");
585         uiButSetFunc(bt, socket_vector_menu_cb, node, snode->nodetree);
586         bt= uiDefButF(block, NUMSLI, 0, "Y ",    0,20,180,20, ns->vec+1, ns->min, ns->max, 10, 0, "");
587         uiButSetFunc(bt, socket_vector_menu_cb, node, snode->nodetree);
588         bt= uiDefButF(block, NUMSLI, 0, "Z ",    0,0,180,20, ns->vec+2, ns->min, ns->max, 10, 0, "");
589         uiButSetFunc(bt, socket_vector_menu_cb, node, snode->nodetree);
590         
591         uiBlockSetDirection(block, UI_TOP);
592         uiEndBlock(C, block);
593         
594         ED_area_tag_redraw(sa);
595         
596         return block;
597 }
598
599 /* not a callback */
600 static void node_draw_preview(bNodePreview *preview, rctf *prv)
601 {
602         float xscale= (prv->xmax-prv->xmin)/((float)preview->xsize);
603         float yscale= (prv->ymax-prv->ymin)/((float)preview->ysize);
604         float tile= (prv->xmax - prv->xmin) / 10.0f;
605         float x, y;
606         
607         /* draw checkerboard backdrop to show alpha */
608         glColor3ub(120, 120, 120);
609         glRectf(prv->xmin, prv->ymin, prv->xmax, prv->ymax);
610         glColor3ub(160, 160, 160);
611         
612         for(y=prv->ymin; y<prv->ymax; y+=tile*2) {
613                 for(x=prv->xmin; x<prv->xmax; x+=tile*2) {
614                         float tilex= tile, tiley= tile;
615
616                         if(x+tile > prv->xmax)
617                                 tilex= prv->xmax-x;
618                         if(y+tile > prv->ymax)
619                                 tiley= prv->ymax-y;
620
621                         glRectf(x, y, x + tilex, y + tiley);
622                 }
623         }
624         for(y=prv->ymin+tile; y<prv->ymax; y+=tile*2) {
625                 for(x=prv->xmin+tile; x<prv->xmax; x+=tile*2) {
626                         float tilex= tile, tiley= tile;
627
628                         if(x+tile > prv->xmax)
629                                 tilex= prv->xmax-x;
630                         if(y+tile > prv->ymax)
631                                 tiley= prv->ymax-y;
632
633                         glRectf(x, y, x + tilex, y + tiley);
634                 }
635         }
636         
637 #ifdef __APPLE__
638 //      if(is_a_really_crappy_nvidia_card()) {  XXX
639 //              float zoomx= curarea->winx/(float)(G.v2d->cur.xmax-G.v2d->cur.xmin);
640 //              float zoomy= curarea->winy/(float)(G.v2d->cur.ymax-G.v2d->cur.ymin);
641 //              glPixelZoom(zoomx*xscale, zoomy*yscale);
642 //      }
643 //      else
644 #endif
645                 glPixelZoom(xscale, yscale);
646
647         glEnable(GL_BLEND);
648         glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );  /* premul graphics */
649         
650         glColor4f(1.0, 1.0, 1.0, 1.0);
651         glaDrawPixelsTex(prv->xmin, prv->ymin, preview->xsize, preview->ysize, GL_FLOAT, preview->rect);
652         
653         glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
654         glDisable(GL_BLEND);
655         glPixelZoom(1.0f, 1.0f);
656
657         UI_ThemeColorShadeAlpha(TH_BACK, -15, +100);
658         fdrawbox(prv->xmin, prv->ymin, prv->xmax, prv->ymax);
659         
660 }
661
662 static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bNode *node)
663 {
664         bNodeSocket *sock;
665         uiBut *bt;
666         rctf *rct= &node->totr;
667         float /*slen,*/ iconofs;
668         int /*ofs,*/ color_id= node_get_colorid(node);
669         char showname[128]; /* 128 used below */
670         View2D *v2d = &ar->v2d;
671         
672         uiSetRoundBox(15-4);
673         ui_dropshadow(rct, BASIS_RAD, snode->aspect, node->flag & SELECT);
674         
675         /* header */
676         if(color_id==TH_NODE)
677                 UI_ThemeColorShade(color_id, -20);
678         else
679                 UI_ThemeColor(color_id);
680                 
681         uiSetRoundBox(3);
682         uiRoundBox(rct->xmin, rct->ymax-NODE_DY, rct->xmax, rct->ymax, BASIS_RAD);
683         
684         /* show/hide icons, note this sequence is copied in editnode.c */
685         iconofs= rct->xmax;
686         
687         if(node->typeinfo->flag & NODE_PREVIEW) {
688                 int icon_id;
689                 
690                 if(node->flag & (NODE_ACTIVE_ID|NODE_DO_OUTPUT))
691                         icon_id= ICON_MATERIAL;
692                 else
693                         icon_id= ICON_MATERIAL_DATA;
694                 iconofs-= 18.0f;
695                 glEnable(GL_BLEND);
696                 UI_icon_draw_aspect(iconofs, rct->ymax-NODE_DY+2, icon_id, snode->aspect, 0.5f);
697                 glDisable(GL_BLEND);
698         }
699         if(node->type == NODE_GROUP) {
700                 
701                 iconofs-= 18.0f;
702                 glEnable(GL_BLEND);
703                 if(node->id->lib) {
704                         float rgb[3] = {1.0f, 0.7f, 0.3f};
705                         UI_icon_draw_aspect_color(iconofs, rct->ymax-NODE_DY+2, ICON_NODE, snode->aspect, rgb);
706                 }
707                 else {
708                         UI_icon_draw_aspect(iconofs, rct->ymax-NODE_DY+2, ICON_NODE, snode->aspect, 0.5f);
709                 }
710                 glDisable(GL_BLEND);
711         }
712         if(node->typeinfo->flag & NODE_OPTIONS) {
713                 iconofs-= 18.0f;
714                 glEnable(GL_BLEND);
715                 UI_icon_draw_aspect(iconofs, rct->ymax-NODE_DY+2, ICON_BUTS, snode->aspect, 0.5f);
716                 glDisable(GL_BLEND);
717         }
718         {       /* always hide/reveal unused sockets */ 
719                 int shade;
720
721                 iconofs-= 18.0f;
722                 // XXX re-enable
723                 /*if(node_has_hidden_sockets(node))
724                         shade= -40;
725                 else*/
726                         shade= -90;
727                 glEnable(GL_BLEND);
728                 UI_icon_draw_aspect(iconofs, rct->ymax-NODE_DY+2, ICON_PLUS, snode->aspect, 0.5f);
729                 glDisable(GL_BLEND);
730         }
731         
732         /* title */
733         if(node->flag & SELECT) 
734                 UI_ThemeColor(TH_TEXT_HI);
735         else
736                 UI_ThemeColorBlendShade(TH_TEXT, color_id, 0.4f, 10);
737         
738         /* open/close entirely? */
739         ui_draw_tria_icon(rct->xmin+8.0f, rct->ymax-NODE_DY+4.0f, snode->aspect, 'v');
740         
741         if(node->flag & SELECT) 
742                 UI_ThemeColor(TH_TEXT_HI);
743         else
744                 UI_ThemeColor(TH_TEXT);
745         
746         if(node->flag & NODE_MUTED)
747                 sprintf(showname, "[%s]", node->name);
748         else if(node->username[0])
749                 sprintf(showname, "(%s) %s", node->username, node->name);
750         else
751                 BLI_strncpy(showname, node->name, 128);
752         
753         uiDefBut(node->block, LABEL, 0, showname, (short)(rct->xmin+15), (short)(rct->ymax-NODE_DY), 
754                          (int)(iconofs - rct->xmin-18.0f), NODE_DY,  NULL, 0, 0, 0, 0, "");
755
756         /* body */
757         UI_ThemeColor4(TH_NODE);
758         glEnable(GL_BLEND);
759         uiSetRoundBox(8);
760         uiRoundBox(rct->xmin, rct->ymin, rct->xmax, rct->ymax-NODE_DY, BASIS_RAD);
761         glDisable(GL_BLEND);
762
763         /* scaling indicator */
764         node_scaling_widget(TH_NODE, snode->aspect, rct->xmax-BASIS_RAD*snode->aspect, rct->ymin, rct->xmax, rct->ymin+BASIS_RAD*snode->aspect);
765
766         /* outline active emphasis */
767         if(node->flag & NODE_ACTIVE) {
768                 glEnable(GL_BLEND);
769                 glColor4ub(200, 200, 200, 140);
770                 uiSetRoundBox(15-4);
771                 gl_round_box(GL_LINE_LOOP, rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD);
772                 glDisable(GL_BLEND);
773         }
774         
775         /* disable lines */
776         if(node->flag & NODE_MUTED)
777                 node_draw_mute_line(v2d, snode, node);
778
779         
780         /* hurmf... another candidate for callback, have to see how this works first */
781         if(node->id && node->block && snode->treetype==NTREE_SHADER)
782                 nodeShaderSynchronizeID(node, 0);
783         
784         /* socket inputs, buttons */
785         for(sock= node->inputs.first; sock; sock= sock->next) {
786                 if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) {
787                         socket_circle_draw(sock, NODE_SOCKSIZE);
788                         
789                         if(node->block && sock->link==NULL) {
790                                 float *butpoin= sock->ns.vec;
791                                 
792                                 if(sock->type==SOCK_VALUE) {
793                                         bt= uiDefButF(node->block, NUM, B_NODE_EXEC, sock->name, 
794                                                   (short)sock->locx+NODE_DYS, (short)(sock->locy)-9, (short)node->width-NODE_DY, 17, 
795                                                   butpoin, sock->ns.min, sock->ns.max, 10, 2, "");
796                                         uiButSetFunc(bt, node_sync_cb, snode, node);
797                                 }
798                                 else if(sock->type==SOCK_VECTOR) {
799                                         uiDefBlockBut(node->block, socket_vector_menu, sock, sock->name, 
800                                                   (short)sock->locx+NODE_DYS, (short)sock->locy-9, (short)node->width-NODE_DY, 17, 
801                                                   "");
802                                 }
803                                 else if(node->block && sock->type==SOCK_RGBA) {
804                                         short labelw= (short)node->width-NODE_DY-40, width;
805                                         
806                                         if(labelw>0) width= 40; else width= (short)node->width-NODE_DY;
807                                         
808                                         bt= uiDefButF(node->block, COL, B_NODE_EXEC, "", 
809                                                 (short)(sock->locx+NODE_DYS), (short)sock->locy-8, width, 15, 
810                                                    butpoin, 0, 0, 0, 0, "");
811                                         uiButSetFunc(bt, node_sync_cb, snode, node);
812                                         
813                                         if(labelw>0) uiDefBut(node->block, LABEL, 0, sock->name, 
814                                                                                    (short)(sock->locx+NODE_DYS) + 40, (short)sock->locy-8, labelw, 15, 
815                                                                                    NULL, 0, 0, 0, 0, "");
816                                 }
817                         }
818                         else {
819                                 
820                                 uiDefBut(node->block, LABEL, 0, sock->name, (short)(sock->locx+3.0f), (short)(sock->locy-9.0f), 
821                                                  (short)(node->width-NODE_DY), NODE_DY,  NULL, 0, 0, 0, 0, "");
822                         }
823                 }
824         }
825         
826         /* socket outputs */
827         for(sock= node->outputs.first; sock; sock= sock->next) {
828                 if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) {
829                         float slen;
830                         int ofs= 0;
831                         
832                         socket_circle_draw(sock, NODE_SOCKSIZE);
833                         
834                         UI_ThemeColor(TH_TEXT);
835                         slen= snode->aspect*UI_GetStringWidth(sock->name);
836                         while(slen > node->width) {
837                                 ofs++;
838                                 slen= snode->aspect*UI_GetStringWidth(sock->name+ofs);
839                         }
840                         
841                         uiDefBut(node->block, LABEL, 0, sock->name+ofs, (short)(sock->locx-15.0f-slen), (short)(sock->locy-9.0f), 
842                                          (short)(node->width-NODE_DY), NODE_DY,  NULL, 0, 0, 0, 0, "");
843                 }
844         }
845         
846         /* preview */
847         if(node->flag & NODE_PREVIEW) {
848                 BLI_lock_thread(LOCK_PREVIEW);
849                 if(node->preview && node->preview->rect)
850                         node_draw_preview(node->preview, &node->prvr);
851                 BLI_unlock_thread(LOCK_PREVIEW);
852         }
853                 
854         uiEndBlock(C, node->block);
855         uiDrawBlock(C, node->block);
856         node->block= NULL;
857 }
858
859 static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, bNode *node)
860 {
861         bNodeSocket *sock;
862         rctf *rct= &node->totr;
863         float dx, centy= 0.5f*(rct->ymax+rct->ymin);
864         float hiddenrad= 0.5f*(rct->ymax-rct->ymin);
865         int color_id= node_get_colorid(node);
866         char showname[128];     /* 128 is used below */
867         
868         /* shadow */
869         uiSetRoundBox(15);
870         ui_dropshadow(rct, hiddenrad, snode->aspect, node->flag & SELECT);
871
872         /* body */
873         UI_ThemeColor(color_id);        
874         uiRoundBox(rct->xmin, rct->ymin, rct->xmax, rct->ymax, hiddenrad);
875         
876         /* outline active emphasis */
877         if(node->flag & NODE_ACTIVE) {
878                 glEnable(GL_BLEND);
879                 glColor4ub(200, 200, 200, 140);
880                 gl_round_box(GL_LINE_LOOP, rct->xmin, rct->ymin, rct->xmax, rct->ymax, hiddenrad);
881                 glDisable(GL_BLEND);
882         }
883         
884         /* title */
885         if(node->flag & SELECT) 
886                 UI_ThemeColor(TH_TEXT_HI);
887         else
888                 UI_ThemeColorBlendShade(TH_TEXT, color_id, 0.4f, 10);
889         
890         /* open entirely icon */
891         ui_draw_tria_icon(rct->xmin+9.0f, centy-6.0f, snode->aspect, 'h');      
892         
893         /* disable lines */
894         if(node->flag & NODE_MUTED)
895                 node_draw_mute_line(&ar->v2d, snode, node);     
896         
897         if(node->flag & SELECT) 
898                 UI_ThemeColor(TH_TEXT_HI);
899         else
900                 UI_ThemeColor(TH_TEXT);
901         
902         if(node->miniwidth>0.0f) {
903
904                 if(node->flag & NODE_MUTED)
905                         sprintf(showname, "[%s]", node->name);
906                 else if(node->username[0])
907                         sprintf(showname, "(%s)%s", node->username, node->name);
908                 else
909                         BLI_strncpy(showname, node->name, 128);
910
911                 uiDefBut(node->block, LABEL, 0, showname, (short)(rct->xmin+15), (short)(centy-10), 
912                                  (int)(rct->xmax - rct->xmin-18.0f -12.0f), NODE_DY,  NULL, 0, 0, 0, 0, "");
913         }       
914
915         /* scale widget thing */
916         UI_ThemeColorShade(color_id, -10);      
917         dx= 10.0f;
918         fdrawline(rct->xmax-dx, centy-4.0f, rct->xmax-dx, centy+4.0f);
919         fdrawline(rct->xmax-dx-3.0f*snode->aspect, centy-4.0f, rct->xmax-dx-3.0f*snode->aspect, centy+4.0f);
920         
921         UI_ThemeColorShade(color_id, +30);
922         dx-= snode->aspect;
923         fdrawline(rct->xmax-dx, centy-4.0f, rct->xmax-dx, centy+4.0f);
924         fdrawline(rct->xmax-dx-3.0f*snode->aspect, centy-4.0f, rct->xmax-dx-3.0f*snode->aspect, centy+4.0f);
925         
926         /* sockets */
927         for(sock= node->inputs.first; sock; sock= sock->next) {
928                 if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)))
929                         socket_circle_draw(sock, NODE_SOCKSIZE);
930         }
931         
932         for(sock= node->outputs.first; sock; sock= sock->next) {
933                 if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)))
934                         socket_circle_draw(sock, NODE_SOCKSIZE);
935         }
936         
937         uiEndBlock(C, node->block);
938         uiDrawBlock(C, node->block);
939         node->block= NULL;
940 }
941
942 static void node_draw_nodetree(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *ntree)
943 {
944         bNode *node;
945         bNodeLink *link;
946         int a;
947         
948         if(ntree==NULL) return;         /* groups... */
949         
950         /* node lines */
951         glEnable(GL_BLEND);
952         glEnable(GL_LINE_SMOOTH);
953         for(link= ntree->links.first; link; link= link->next)
954                 node_draw_link(&ar->v2d, snode, link);
955         glDisable(GL_LINE_SMOOTH);
956         glDisable(GL_BLEND);
957         
958         /* not selected first */
959         for(a=0, node= ntree->nodes.first; node; node= node->next, a++) {
960                 node->nr= a;            /* index of node in list, used for exec event code */
961                 if(!(node->flag & SELECT)) {
962                         if(node->flag & NODE_GROUP_EDIT);
963                         else if(node->flag & NODE_HIDDEN)
964                                 node_draw_hidden(C, ar, snode, node);
965                         else
966                                 node_draw_basis(C, ar, snode, node);
967                 }
968         }
969         
970         /* selected */
971         for(node= ntree->nodes.first; node; node= node->next) {
972                 if(node->flag & SELECT) {
973                         if(node->flag & NODE_GROUP_EDIT);
974                         else if(node->flag & NODE_HIDDEN)
975                                 node_draw_hidden(C, ar, snode, node);
976                         else
977                                 node_draw_basis(C, ar, snode, node);
978                 }
979         }       
980 }
981
982 /* fake links from groupnode to internal nodes */
983 static void node_draw_group_links(View2D *v2d, SpaceNode *snode, bNode *gnode)
984 {
985         bNodeLink fakelink;
986         bNodeSocket *sock;
987         
988         glEnable(GL_BLEND);
989         glEnable(GL_LINE_SMOOTH);
990         
991         fakelink.tonode= fakelink.fromnode= gnode;
992         
993         for(sock= gnode->inputs.first; sock; sock= sock->next) {
994                 if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) {
995                         if(sock->tosock) {
996                                 fakelink.fromsock= sock;
997                                 fakelink.tosock= sock->tosock;
998                                 node_draw_link(v2d, snode, &fakelink);
999                         }
1000                 }
1001         }
1002         
1003         for(sock= gnode->outputs.first; sock; sock= sock->next) {
1004                 if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) {
1005                         if(sock->tosock) {
1006                                 fakelink.tosock= sock;
1007                                 fakelink.fromsock= sock->tosock;
1008                                 node_draw_link(v2d, snode, &fakelink);
1009                         }
1010                 }
1011         }
1012         
1013         glDisable(GL_BLEND);
1014         glDisable(GL_LINE_SMOOTH);
1015 }
1016
1017 /* groups are, on creation, centered around 0,0 */
1018 static void node_draw_group(const bContext *C, ARegion *ar, SpaceNode *snode, bNode *gnode)
1019 {
1020         bNodeTree *ngroup= (bNodeTree *)gnode->id;
1021         bNodeSocket *sock;
1022         rctf rect= gnode->totr;
1023         char showname[128];
1024         
1025         /* backdrop header */
1026         glEnable(GL_BLEND);
1027         uiSetRoundBox(3);
1028         UI_ThemeColorShadeAlpha(TH_NODE_GROUP, 0, -70);
1029         gl_round_box(GL_POLYGON, rect.xmin, rect.ymax, rect.xmax, rect.ymax+NODE_DY, BASIS_RAD);
1030         
1031         /* backdrop body */
1032         UI_ThemeColorShadeAlpha(TH_BACK, -8, -70);
1033         uiSetRoundBox(12);
1034         gl_round_box(GL_POLYGON, rect.xmin, rect.ymin, rect.xmax, rect.ymax, BASIS_RAD);
1035         
1036         /* selection outline */
1037         uiSetRoundBox(15);
1038         glColor4ub(200, 200, 200, 140);
1039         glEnable( GL_LINE_SMOOTH );
1040         gl_round_box(GL_LINE_LOOP, rect.xmin, rect.ymin, rect.xmax, rect.ymax+NODE_DY, BASIS_RAD);
1041         glDisable( GL_LINE_SMOOTH );
1042         glDisable(GL_BLEND);
1043         
1044         /* backdrop title */
1045         UI_ThemeColor(TH_TEXT_HI);
1046
1047         if(gnode->username[0]) {
1048                 strcpy(showname,"(");
1049                 strcat(showname, gnode->username);
1050                 strcat(showname,") ");
1051                 strcat(showname, ngroup->id.name+2);
1052         }
1053         else
1054                 strcpy(showname, ngroup->id.name+2);
1055
1056         UI_DrawString(rect.xmin+8.0f, rect.ymax+5.0f, showname);
1057         
1058         /* links from groupsockets to the internal nodes */
1059         node_draw_group_links(&ar->v2d, snode, gnode);
1060         
1061         /* group sockets */
1062         for(sock= gnode->inputs.first; sock; sock= sock->next)
1063                 if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)))
1064                         socket_circle_draw(sock, NODE_SOCKSIZE);
1065         for(sock= gnode->outputs.first; sock; sock= sock->next)
1066                 if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)))
1067                         socket_circle_draw(sock, NODE_SOCKSIZE);
1068
1069         /* and finally the whole tree */
1070         node_draw_nodetree(C, ar, snode, ngroup);
1071 }
1072
1073 void drawnodespace(const bContext *C, ARegion *ar, View2D *v2d)
1074 {
1075         float col[3];
1076         View2DScrollers *scrollers;
1077         SpaceNode *snode= CTX_wm_space_node(C);
1078         
1079         UI_GetThemeColor3fv(TH_BACK, col);
1080         glClearColor(col[0], col[1], col[2], 0);
1081         glClear(GL_COLOR_BUFFER_BIT);
1082
1083         UI_view2d_view_ortho(C, v2d);
1084         
1085         //uiFreeBlocksWin(&sa->uiblocks, sa->win);
1086
1087         /* only set once */
1088         glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1089         glEnable(GL_MAP1_VERTEX_3);
1090
1091         /* aspect+font, set each time */
1092         snode->aspect= (v2d->cur.xmax - v2d->cur.xmin)/((float)ar->winx);
1093         // XXX snode->curfont= uiSetCurFont_ext(snode->aspect);
1094
1095         UI_view2d_constant_grid_draw(C, v2d);
1096         /* backdrop */
1097         draw_nodespace_back_pix(ar, snode);
1098         
1099         /* nodes */
1100         snode_set_context(snode, CTX_data_scene(C));
1101         
1102         if(snode->nodetree) {
1103                 bNode *node;
1104                 
1105                 /* for now, we set drawing coordinates on each redraw */
1106                 for(node= snode->nodetree->nodes.first; node; node= node->next) {
1107                         if(node->flag & NODE_GROUP_EDIT)
1108                                 node_update_group(C, snode->nodetree, node);
1109                         else if(node->flag & NODE_HIDDEN)
1110                                 node_update_hidden(C, node);
1111                         else
1112                                 node_update(C, snode->nodetree, node);
1113                 }
1114
1115                 node_draw_nodetree(C, ar, snode, snode->nodetree);
1116                         
1117                 /* active group */
1118                 for(node= snode->nodetree->nodes.first; node; node= node->next) {
1119                         if(node->flag & NODE_GROUP_EDIT)
1120                                 node_draw_group(C, ar, snode, node);
1121                 }
1122         }
1123         
1124         /* draw grease-pencil ('canvas' strokes) */
1125         /*if ((snode->flag & SNODE_DISPGP) && (snode->nodetree))
1126                 draw_gpencil_2dview(sa, 1);*/
1127         
1128         /* restore viewport (not needed yet) */
1129         /*mywinset(sa->win);*/
1130
1131         /* ortho at pixel level curarea */
1132         /*myortho2(-0.375, sa->winx-0.375, -0.375, sa->winy-0.375);*/
1133         
1134         /* draw grease-pencil (screen strokes) */
1135         /*if ((snode->flag & SNODE_DISPGP) && (snode->nodetree))
1136                 draw_gpencil_2dview(sa, 0);*/
1137
1138         //draw_area_emboss(sa);
1139         
1140         /* it is important to end a view in a transform compatible with buttons */
1141         /*bwin_scalematrix(sa->win, snode->blockscale, snode->blockscale, snode->blockscale);
1142         nodes_blockhandlers(sa);*/
1143         
1144         //curarea->win_swap= WIN_BACK_OK;
1145         
1146         /* in the end, this is a delayed previewrender test, to allow buttons to be first */
1147         /*if(snode->flag & SNODE_DO_PREVIEW) {
1148                 addafterqueue(sa->win, RENDERPREVIEW, 1);
1149                 snode->flag &= ~SNODE_DO_PREVIEW;
1150         }*/
1151         
1152         
1153         
1154         /* reset view matrix */
1155         UI_view2d_view_restore(C);
1156         
1157         /* scrollers */
1158         scrollers= UI_view2d_scrollers_calc(C, v2d, 10, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
1159         UI_view2d_scrollers_draw(C, v2d, scrollers);
1160         UI_view2d_scrollers_free(scrollers);
1161 }