2.5
[blender.git] / source / blender / editors / screen / screen_edit.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  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 #include <string.h>
28
29 #include "MEM_guardedalloc.h"
30
31 #include "DNA_vec_types.h"
32 #include "DNA_scene_types.h"
33 #include "DNA_screen_types.h"
34 #include "DNA_texture_types.h"
35
36 #include "BLI_blenlib.h"
37
38 #include "BKE_context.h"
39 #include "BKE_global.h"
40 #include "BKE_library.h"
41 #include "BKE_main.h"
42 #include "BKE_node.h"
43 #include "BKE_screen.h"
44 #include "BKE_scene.h"
45 #include "BKE_utildefines.h"
46
47 #include "BIF_gl.h"
48 #include "BIF_glutil.h"
49
50 #include "WM_api.h"
51 #include "WM_types.h"
52
53 #include "ED_screen.h"
54 #include "ED_screen_types.h"
55
56 #include "wm_subwindow.h"
57
58 #include "screen_intern.h"      /* own module include */
59
60
61 /* ******************* screen vert, edge, area managing *********************** */
62
63 static ScrVert *screen_addvert(bScreen *sc, short x, short y)
64 {
65         ScrVert *sv= MEM_callocN(sizeof(ScrVert), "addscrvert");
66         sv->vec.x= x;
67         sv->vec.y= y;
68         
69         BLI_addtail(&sc->vertbase, sv);
70         return sv;
71 }
72
73 static void sortscrvert(ScrVert **v1, ScrVert **v2)
74 {
75         ScrVert *tmp;
76         
77         if (*v1 > *v2) {
78                 tmp= *v1;
79                 *v1= *v2;
80                 *v2= tmp;       
81         }
82 }
83
84 static ScrEdge *screen_addedge(bScreen *sc, ScrVert *v1, ScrVert *v2)
85 {
86         ScrEdge *se= MEM_callocN(sizeof(ScrEdge), "addscredge");
87         
88         sortscrvert(&v1, &v2);
89         se->v1= v1;
90         se->v2= v2;
91         
92         BLI_addtail(&sc->edgebase, se);
93         return se;
94 }
95
96
97 ScrEdge *screen_findedge(bScreen *sc, ScrVert *v1, ScrVert *v2)
98 {
99         ScrEdge *se;
100         
101         sortscrvert(&v1, &v2);
102         for (se= sc->edgebase.first; se; se= se->next)
103                 if(se->v1==v1 && se->v2==v2)
104                         return se;
105         
106         return NULL;
107 }
108
109 void removedouble_scrverts(bScreen *sc)
110 {
111         ScrVert *v1, *verg;
112         ScrEdge *se;
113         ScrArea *sa;
114         
115         verg= sc->vertbase.first;
116         while(verg) {
117                 if(verg->newv==NULL) {  /* !!! */
118                         v1= verg->next;
119                         while(v1) {
120                                 if(v1->newv==NULL) {    /* !?! */
121                                         if(v1->vec.x==verg->vec.x && v1->vec.y==verg->vec.y) {
122                                                 /* printf("doublevert\n"); */
123                                                 v1->newv= verg;
124                                         }
125                                 }
126                                 v1= v1->next;
127                         }
128                 }
129                 verg= verg->next;
130         }
131
132         /* replace pointers in edges and faces */
133         se= sc->edgebase.first;
134         while(se) {
135                 if(se->v1->newv) se->v1= se->v1->newv;
136                 if(se->v2->newv) se->v2= se->v2->newv;
137                 /* edges changed: so.... */
138                 sortscrvert(&(se->v1), &(se->v2));
139                 se= se->next;
140         }
141         sa= sc->areabase.first;
142         while(sa) {
143                 if(sa->v1->newv) sa->v1= sa->v1->newv;
144                 if(sa->v2->newv) sa->v2= sa->v2->newv;
145                 if(sa->v3->newv) sa->v3= sa->v3->newv;
146                 if(sa->v4->newv) sa->v4= sa->v4->newv;
147                 sa= sa->next;
148         }
149
150         /* remove */
151         verg= sc->vertbase.first;
152         while(verg) {
153                 v1= verg->next;
154                 if(verg->newv) {
155                         BLI_remlink(&sc->vertbase, verg);
156                         MEM_freeN(verg);
157                 }
158                 verg= v1;
159         }
160
161 }
162
163 void removenotused_scrverts(bScreen *sc)
164 {
165         ScrVert *sv, *svn;
166         ScrEdge *se;
167         
168         /* we assume edges are ok */
169         
170         se= sc->edgebase.first;
171         while(se) {
172                 se->v1->flag= 1;
173                 se->v2->flag= 1;
174                 se= se->next;
175         }
176         
177         sv= sc->vertbase.first;
178         while(sv) {
179                 svn= sv->next;
180                 if(sv->flag==0) {
181                         BLI_remlink(&sc->vertbase, sv);
182                         MEM_freeN(sv);
183                 }
184                 else sv->flag= 0;
185                 sv= svn;
186         }
187 }
188
189 void removedouble_scredges(bScreen *sc)
190 {
191         ScrEdge *verg, *se, *sn;
192         
193         /* compare */
194         verg= sc->edgebase.first;
195         while(verg) {
196                 se= verg->next;
197                 while(se) {
198                         sn= se->next;
199                         if(verg->v1==se->v1 && verg->v2==se->v2) {
200                                 BLI_remlink(&sc->edgebase, se);
201                                 MEM_freeN(se);
202                         }
203                         se= sn;
204                 }
205                 verg= verg->next;
206         }
207 }
208
209 void removenotused_scredges(bScreen *sc)
210 {
211         ScrEdge *se, *sen;
212         ScrArea *sa;
213         int a=0;
214         
215         /* sets flags when edge is used in area */
216         sa= sc->areabase.first;
217         while(sa) {
218                 se= screen_findedge(sc, sa->v1, sa->v2);
219                 if(se==0) printf("error: area %d edge 1 doesn't exist\n", a);
220                 else se->flag= 1;
221                 se= screen_findedge(sc, sa->v2, sa->v3);
222                 if(se==0) printf("error: area %d edge 2 doesn't exist\n", a);
223                 else se->flag= 1;
224                 se= screen_findedge(sc, sa->v3, sa->v4);
225                 if(se==0) printf("error: area %d edge 3 doesn't exist\n", a);
226                 else se->flag= 1;
227                 se= screen_findedge(sc, sa->v4, sa->v1);
228                 if(se==0) printf("error: area %d edge 4 doesn't exist\n", a);
229                 else se->flag= 1;
230                 sa= sa->next;
231                 a++;
232         }
233         se= sc->edgebase.first;
234         while(se) {
235                 sen= se->next;
236                 if(se->flag==0) {
237                         BLI_remlink(&sc->edgebase, se);
238                         MEM_freeN(se);
239                 }
240                 else se->flag= 0;
241                 se= sen;
242         }
243 }
244
245 int scredge_is_horizontal(ScrEdge *se)
246 {
247         return (se->v1->vec.y == se->v2->vec.y);
248 }
249
250 ScrEdge *screen_find_active_scredge(bScreen *sc, int mx, int my)
251 {
252         ScrEdge *se;
253         
254         for (se= sc->edgebase.first; se; se= se->next) {
255                 if (scredge_is_horizontal(se)) {
256                         short min, max;
257                         min= MIN2(se->v1->vec.x, se->v2->vec.x);
258                         max= MAX2(se->v1->vec.x, se->v2->vec.x);
259                         
260                         if (abs(my-se->v1->vec.y)<=2 && mx>=min && mx<=max)
261                                 return se;
262                 } 
263                 else {
264                         short min, max;
265                         min= MIN2(se->v1->vec.y, se->v2->vec.y);
266                         max= MAX2(se->v1->vec.y, se->v2->vec.y);
267                         
268                         if (abs(mx-se->v1->vec.x)<=2 && my>=min && my<=max)
269                                 return se;
270                 }
271         }
272         
273         return NULL;
274 }
275
276
277
278 /* adds no space data */
279 static ScrArea *screen_addarea(bScreen *sc, ScrVert *v1, ScrVert *v2, ScrVert *v3, ScrVert *v4, short headertype, short spacetype)
280 {
281         ScrArea *sa= MEM_callocN(sizeof(ScrArea), "addscrarea");
282         sa->v1= v1;
283         sa->v2= v2;
284         sa->v3= v3;
285         sa->v4= v4;
286         sa->headertype= headertype;
287         sa->spacetype= sa->butspacetype= spacetype;
288         
289         BLI_addtail(&sc->areabase, sa);
290         
291         return sa;
292 }
293
294 static void screen_delarea(bContext *C, bScreen *sc, ScrArea *sa)
295 {
296         
297         ED_area_exit(C, sa);
298         
299         BKE_screen_area_free(sa);
300         
301         BLI_remlink(&sc->areabase, sa);
302         MEM_freeN(sa);
303 }
304
305 /* return 0: no split possible */
306 /* else return (integer) screencoordinate split point */
307 static short testsplitpoint(wmWindow *win, ScrArea *sa, char dir, float fac)
308 {
309         short x, y;
310         
311         // area big enough?
312         if(dir=='v' && (sa->v4->vec.x- sa->v1->vec.x <= 2*AREAMINX)) return 0;
313         if(dir=='h' && (sa->v2->vec.y- sa->v1->vec.y <= 2*AREAMINY)) return 0;
314         
315         // to be sure
316         if(fac<0.0) fac= 0.0;
317         if(fac>1.0) fac= 1.0;
318         
319         if(dir=='h') {
320                 y= sa->v1->vec.y+ fac*(sa->v2->vec.y- sa->v1->vec.y);
321                 
322                 if(y- sa->v1->vec.y < AREAMINY) 
323                         y= sa->v1->vec.y+ AREAMINY;
324                 else if(sa->v2->vec.y- y < AREAMINY) 
325                         y= sa->v2->vec.y- AREAMINY;
326                 else y-= (y % AREAGRID);
327                 
328                 return y;
329         }
330         else {
331                 x= sa->v1->vec.x+ fac*(sa->v4->vec.x- sa->v1->vec.x);
332                 
333                 if(x- sa->v1->vec.x < AREAMINX) 
334                         x= sa->v1->vec.x+ AREAMINX;
335                 else if(sa->v4->vec.x- x < AREAMINX) 
336                         x= sa->v4->vec.x- AREAMINX;
337                 else x-= (x % AREAGRID);
338                 
339                 return x;
340         }
341 }
342
343 ScrArea *area_split(wmWindow *win, bScreen *sc, ScrArea *sa, char dir, float fac)
344 {
345         ScrArea *newa=NULL;
346         ScrVert *sv1, *sv2;
347         short split;
348         
349         if(sa==NULL) return NULL;
350         
351         split= testsplitpoint(win, sa, dir, fac);
352         if(split==0) return NULL;
353         
354         if(dir=='h') {
355                 /* new vertices */
356                 sv1= screen_addvert(sc, sa->v1->vec.x, split);
357                 sv2= screen_addvert(sc, sa->v4->vec.x, split);
358                 
359                 /* new edges */
360                 screen_addedge(sc, sa->v1, sv1);
361                 screen_addedge(sc, sv1, sa->v2);
362                 screen_addedge(sc, sa->v3, sv2);
363                 screen_addedge(sc, sv2, sa->v4);
364                 screen_addedge(sc, sv1, sv2);
365                 
366                 /* new areas: top */
367                 newa= screen_addarea(sc, sv1, sa->v2, sa->v3, sv2, sa->headertype, sa->spacetype);
368                 area_copy_data(newa, sa, 0);
369                 
370                 /* area below */
371                 sa->v2= sv1;
372                 sa->v3= sv2;
373                 
374         }
375         else {
376                 /* new vertices */
377                 sv1= screen_addvert(sc, split, sa->v1->vec.y);
378                 sv2= screen_addvert(sc, split, sa->v2->vec.y);
379                 
380                 /* new edges */
381                 screen_addedge(sc, sa->v1, sv1);
382                 screen_addedge(sc, sv1, sa->v4);
383                 screen_addedge(sc, sa->v2, sv2);
384                 screen_addedge(sc, sv2, sa->v3);
385                 screen_addedge(sc, sv1, sv2);
386                 
387                 /* new areas: left */
388                 newa= screen_addarea(sc, sa->v1, sa->v2, sv2, sv1, sa->headertype, sa->spacetype);
389                 area_copy_data(newa, sa, 0);
390                 
391                 /* area right */
392                 sa->v1= sv1;
393                 sa->v2= sv2;
394         }
395         
396         /* remove double vertices en edges */
397         removedouble_scrverts(sc);
398         removedouble_scredges(sc);
399         removenotused_scredges(sc);
400         
401         return newa;
402 }
403
404 /* empty screen, with 1 dummy area without spacedata */
405 /* uses window size */
406 bScreen *screen_add(wmWindow *win, Scene *scene, char *name)
407 {
408         bScreen *sc;
409         ScrVert *sv1, *sv2, *sv3, *sv4;
410         
411         sc= alloc_libblock(&G.main->screen, ID_SCR, name);
412         sc->scene= scene;
413         sc->do_refresh= 1;
414         
415         sv1= screen_addvert(sc, 0, 0);
416         sv2= screen_addvert(sc, 0, win->sizey-1);
417         sv3= screen_addvert(sc, win->sizex-1, win->sizey-1);
418         sv4= screen_addvert(sc, win->sizex-1, 0);
419         
420         screen_addedge(sc, sv1, sv2);
421         screen_addedge(sc, sv2, sv3);
422         screen_addedge(sc, sv3, sv4);
423         screen_addedge(sc, sv4, sv1);
424         
425         /* dummy type, no spacedata */
426         screen_addarea(sc, sv1, sv2, sv3, sv4, HEADERDOWN, SPACE_EMPTY);
427                 
428         return sc;
429 }
430
431 static void screen_copy(bScreen *to, bScreen *from)
432 {
433         ScrVert *s1, *s2;
434         ScrEdge *se;
435         ScrArea *sa, *saf;
436         
437         /* free contents of 'to', is from blenkernel screen.c */
438         free_screen(to);
439         
440         BLI_duplicatelist(&to->vertbase, &from->vertbase);
441         BLI_duplicatelist(&to->edgebase, &from->edgebase);
442         BLI_duplicatelist(&to->areabase, &from->areabase);
443         to->regionbase.first= to->regionbase.last= NULL;
444         
445         s2= to->vertbase.first;
446         for(s1= from->vertbase.first; s1; s1= s1->next, s2= s2->next) {
447                 s1->newv= s2;
448         }
449         
450         for(se= to->edgebase.first; se; se= se->next) {
451                 se->v1= se->v1->newv;
452                 se->v2= se->v2->newv;
453                 sortscrvert(&(se->v1), &(se->v2));
454         }
455         
456         saf= from->areabase.first;
457         for(sa= to->areabase.first; sa; sa= sa->next, saf= saf->next) {
458                 sa->v1= sa->v1->newv;
459                 sa->v2= sa->v2->newv;
460                 sa->v3= sa->v3->newv;
461                 sa->v4= sa->v4->newv;
462                 
463                 sa->spacedata.first= sa->spacedata.last= NULL;
464                 sa->regionbase.first= sa->regionbase.last= NULL;
465                 sa->actionzones.first= sa->actionzones.last= NULL;
466                 sa->scriptlink.totscript= 0;
467                 
468                 area_copy_data(sa, saf, 0);
469         }
470         
471         /* put at zero (needed?) */
472         for(s1= from->vertbase.first; s1; s1= s1->next)
473                 s1->newv= NULL;
474
475 }
476
477
478 /* with sa as center, sb is located at: 0=W, 1=N, 2=E, 3=S */
479 /* -1 = not valid check */
480 /* used with join operator */
481 int area_getorientation(bScreen *screen, ScrArea *sa, ScrArea *sb)
482 {
483         ScrVert *sav1, *sav2, *sav3, *sav4;
484         ScrVert *sbv1, *sbv2, *sbv3, *sbv4;
485
486         if(sa==NULL || sb==NULL) return -1;
487
488         sav1= sa->v1;
489         sav2= sa->v2;
490         sav3= sa->v3;
491         sav4= sa->v4;
492         sbv1= sb->v1;
493         sbv2= sb->v2;
494         sbv3= sb->v3;
495         sbv4= sb->v4;
496         
497         if(sav1==sbv4 && sav2==sbv3) { /* sa to right of sb = W */
498                 return 0;
499         }
500         else if(sav2==sbv1 && sav3==sbv4) { /* sa to bottom of sb = N */
501                 return 1;
502         }
503         else if(sav3==sbv2 && sav4==sbv1) { /* sa to left of sb = E */
504                 return 2;
505         }
506         else if(sav1==sbv2 && sav4==sbv3) { /* sa on top of sb = S*/
507                 return 3;
508         }
509         
510         return -1;
511 }
512
513 /* Helper function to join 2 areas, it has a return value, 0=failed 1=success
514 *       used by the split, join operators
515 */
516 int screen_area_join(bContext *C, bScreen* scr, ScrArea *sa1, ScrArea *sa2) 
517 {
518         int dir;
519         
520         dir = area_getorientation(scr, sa1, sa2);
521         /*printf("dir is : %i \n", dir);*/
522         
523         if (dir < 0)
524         {
525                 if (sa1 ) sa1->flag &= ~AREA_FLAG_DRAWJOINFROM;
526                 if (sa2 ) sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
527                 return 0;
528         }
529         
530         if(dir == 0) {
531                 sa1->v1= sa2->v1;
532                 sa1->v2= sa2->v2;
533                 screen_addedge(scr, sa1->v2, sa1->v3);
534                 screen_addedge(scr, sa1->v1, sa1->v4);
535         }
536         else if(dir == 1) {
537                 sa1->v2= sa2->v2;
538                 sa1->v3= sa2->v3;
539                 screen_addedge(scr, sa1->v1, sa1->v2);
540                 screen_addedge(scr, sa1->v3, sa1->v4);
541         }
542         else if(dir == 2) {
543                 sa1->v3= sa2->v3;
544                 sa1->v4= sa2->v4;
545                 screen_addedge(scr, sa1->v2, sa1->v3);
546                 screen_addedge(scr, sa1->v1, sa1->v4);
547         }
548         else if(dir == 3) {
549                 sa1->v1= sa2->v1;
550                 sa1->v4= sa2->v4;
551                 screen_addedge(scr, sa1->v1, sa1->v2);
552                 screen_addedge(scr, sa1->v3, sa1->v4);
553         }
554         
555         screen_delarea(C, scr, sa2);
556         removedouble_scrverts(scr);
557         sa1->flag &= ~AREA_FLAG_DRAWJOINFROM;
558         
559         return 1;
560 }
561
562 void select_connected_scredge(bScreen *sc, ScrEdge *edge)
563 {
564         ScrEdge *se;
565         ScrVert *sv;
566         int oneselected;
567         char dir;
568         
569         /* select connected, only in the right direction */
570         /* 'dir' is the direction of EDGE */
571         
572         if(edge->v1->vec.x==edge->v2->vec.x) dir= 'v';
573         else dir= 'h';
574         
575         sv= sc->vertbase.first;
576         while(sv) {
577                 sv->flag = 0;
578                 sv= sv->next;
579         }
580         
581         edge->v1->flag= 1;
582         edge->v2->flag= 1;
583         
584         oneselected= 1;
585         while(oneselected) {
586                 se= sc->edgebase.first;
587                 oneselected= 0;
588                 while(se) {
589                         if(se->v1->flag + se->v2->flag==1) {
590                                 if(dir=='h') if(se->v1->vec.y==se->v2->vec.y) {
591                                         se->v1->flag= se->v2->flag= 1;
592                                         oneselected= 1;
593                                 }
594                                         if(dir=='v') if(se->v1->vec.x==se->v2->vec.x) {
595                                                 se->v1->flag= se->v2->flag= 1;
596                                                 oneselected= 1;
597                                         }
598                         }
599                                 se= se->next;
600                 }
601         }
602 }
603
604 /* test if screen vertices should be scaled */
605 static void screen_test_scale(bScreen *sc, int winsizex, int winsizey)
606 {
607         ScrVert *sv=NULL;
608         ScrArea *sa;
609         int sizex, sizey;
610         float facx, facy, tempf, min[2], max[2];
611         
612         /* calculate size */
613         min[0]= min[1]= 10000.0f;
614         max[0]= max[1]= 0.0f;
615         
616         for(sv= sc->vertbase.first; sv; sv= sv->next) {
617                 min[0]= MIN2(min[0], sv->vec.x);
618                 min[1]= MIN2(min[1], sv->vec.y);
619                 max[0]= MAX2(max[0], sv->vec.x);
620                 max[1]= MAX2(max[1], sv->vec.y);
621         }
622         
623         /* always make 0.0 left under */
624         for(sv= sc->vertbase.first; sv; sv= sv->next) {
625                 sv->vec.x -= min[0];
626                 sv->vec.y -= min[1];
627         }
628         
629         sizex= max[0]-min[0];
630         sizey= max[1]-min[1];
631         
632         if(sizex!= winsizex || sizey!= winsizey) {
633                 facx= winsizex;
634                 facx/= (float)sizex;
635                 facy= winsizey;
636                 facy/= (float)sizey;
637                 
638                 /* make sure it fits! */
639                 for(sv= sc->vertbase.first; sv; sv= sv->next) {
640                         tempf= ((float)sv->vec.x)*facx;
641                         sv->vec.x= (short)(tempf+0.5);
642                         sv->vec.x+= AREAGRID-1;
643                         sv->vec.x-=  (sv->vec.x % AREAGRID); 
644                         
645                         CLAMP(sv->vec.x, 0, winsizex);
646                         
647                         tempf= ((float)sv->vec.y )*facy;
648                         sv->vec.y= (short)(tempf+0.5);
649                         sv->vec.y+= AREAGRID-1;
650                         sv->vec.y-=  (sv->vec.y % AREAGRID); 
651                         
652                         CLAMP(sv->vec.y, 0, winsizey);
653                 }
654         }
655         
656         /* test for collapsed areas. This could happen in some blender version... */
657         /* ton: removed option now, it needs Context... */
658         
659         /* make each window at least HEADERY high */
660         for(sa= sc->areabase.first; sa; sa= sa->next) {
661                 int headery= HEADERY+1;
662                 
663                 if(sa->v1->vec.y+headery > sa->v2->vec.y) {
664                         /* lower edge */
665                         ScrEdge *se= screen_findedge(sc, sa->v4, sa->v1);
666                         if(se && sa->v1!=sa->v2 ) {
667                                 int yval;
668                                 
669                                 select_connected_scredge(sc, se);
670                                 
671                                 /* all selected vertices get the right offset */
672                                 yval= sa->v2->vec.y-headery;
673                                 sv= sc->vertbase.first;
674                                 while(sv) {
675                                         /* if is a collapsed area */
676                                         if(sv!=sa->v2 && sv!=sa->v3) {
677                                                 if(sv->flag) sv->vec.y= yval;
678                                         }
679                                         sv= sv->next;
680                                 }
681                         }
682                 }
683         }
684         
685 }
686
687 /* *********************** DRAWING **************************************** */
688
689
690 #define SCR_BACK 0.55
691 #define SCR_ROUND 12
692
693 /* draw vertical shape visualising future joining (left as well
694  * right direction of future joining) */
695 static void draw_horizontal_join_shape(ScrArea *sa, char dir)
696 {
697         vec2f points[10];
698         short i;
699         float w, h;
700         float width = sa->v3->vec.x - sa->v1->vec.x;
701         float height = sa->v3->vec.y - sa->v1->vec.y;
702
703         if(height<width) {
704                 h = height/8;
705                 w = height/4;
706         }
707         else {
708                 h = width/8;
709                 w = width/4;
710         }
711
712         points[0].x = sa->v1->vec.x;
713         points[0].y = sa->v1->vec.y + height/2;
714
715         points[1].x = sa->v1->vec.x;
716         points[1].y = sa->v1->vec.y;
717
718         points[2].x = sa->v4->vec.x - w;
719         points[2].y = sa->v4->vec.y;
720
721         points[3].x = sa->v4->vec.x - w;
722         points[3].y = sa->v4->vec.y + height/2 - 2*h;
723
724         points[4].x = sa->v4->vec.x - 2*w;
725         points[4].y = sa->v4->vec.y + height/2;
726
727         points[5].x = sa->v4->vec.x - w;
728         points[5].y = sa->v4->vec.y + height/2 + 2*h;
729
730         points[6].x = sa->v3->vec.x - w;
731         points[6].y = sa->v3->vec.y;
732
733         points[7].x = sa->v2->vec.x;
734         points[7].y = sa->v2->vec.y;
735
736         points[8].x = sa->v4->vec.x;
737         points[8].y = sa->v4->vec.y + height/2 - h;
738
739         points[9].x = sa->v4->vec.x;
740         points[9].y = sa->v4->vec.y + height/2 + h;
741
742         if(dir=='l') {
743                 /* when direction is left, then we flip direction of arrow */
744                 float cx = sa->v1->vec.x + width;
745                 for(i=0;i<10;i++) {
746                         points[i].x -= cx;
747                         points[i].x = -points[i].x;
748                         points[i].x += sa->v1->vec.x;
749                 }
750         }
751
752         glBegin(GL_POLYGON);
753         for(i=0;i<5;i++)
754                 glVertex2f(points[i].x, points[i].y);
755         glEnd();
756         glBegin(GL_POLYGON);
757         for(i=4;i<8;i++)
758                 glVertex2f(points[i].x, points[i].y);
759         glVertex2f(points[0].x, points[0].y);
760         glEnd();
761
762         glRectf(points[2].x, points[2].y, points[8].x, points[8].y);
763         glRectf(points[6].x, points[6].y, points[9].x, points[9].y);
764 }
765
766 /* draw vertical shape visualising future joining (up/down direction) */
767 static void draw_vertical_join_shape(ScrArea *sa, char dir)
768 {
769         vec2f points[10];
770         short i;
771         float w, h;
772         float width = sa->v3->vec.x - sa->v1->vec.x;
773         float height = sa->v3->vec.y - sa->v1->vec.y;
774
775         if(height<width) {
776                 h = height/4;
777                 w = height/8;
778         }
779         else {
780                 h = width/4;
781                 w = width/8;
782         }
783
784         points[0].x = sa->v1->vec.x + width/2;
785         points[0].y = sa->v3->vec.y;
786
787         points[1].x = sa->v2->vec.x;
788         points[1].y = sa->v2->vec.y;
789
790         points[2].x = sa->v1->vec.x;
791         points[2].y = sa->v1->vec.y + h;
792
793         points[3].x = sa->v1->vec.x + width/2 - 2*w;
794         points[3].y = sa->v1->vec.y + h;
795
796         points[4].x = sa->v1->vec.x + width/2;
797         points[4].y = sa->v1->vec.y + 2*h;
798
799         points[5].x = sa->v1->vec.x + width/2 + 2*w;
800         points[5].y = sa->v1->vec.y + h;
801
802         points[6].x = sa->v4->vec.x;
803         points[6].y = sa->v4->vec.y + h;
804         
805         points[7].x = sa->v3->vec.x;
806         points[7].y = sa->v3->vec.y;
807
808         points[8].x = sa->v1->vec.x + width/2 - w;
809         points[8].y = sa->v1->vec.y;
810
811         points[9].x = sa->v1->vec.x + width/2 + w;
812         points[9].y = sa->v1->vec.y;
813
814         if(dir=='u') {
815                 /* when direction is up, then we flip direction of arrow */
816                 float cy = sa->v1->vec.y + height;
817                 for(i=0;i<10;i++) {
818                         points[i].y -= cy;
819                         points[i].y = -points[i].y;
820                         points[i].y += sa->v1->vec.y;
821                 }
822         }
823
824         glBegin(GL_POLYGON);
825         for(i=0;i<5;i++)
826                 glVertex2f(points[i].x, points[i].y);
827         glEnd();
828         glBegin(GL_POLYGON);
829         for(i=4;i<8;i++)
830                 glVertex2f(points[i].x, points[i].y);
831         glVertex2f(points[0].x, points[0].y);
832         glEnd();
833
834         glRectf(points[2].x, points[2].y, points[8].x, points[8].y);
835         glRectf(points[6].x, points[6].y, points[9].x, points[9].y);
836 }
837
838 /* draw join shape due to direction of joining */
839 static void draw_join_shape(ScrArea *sa, char dir)
840 {
841         if(dir=='u' || dir=='d')
842                 draw_vertical_join_shape(sa, dir);
843         else
844                 draw_horizontal_join_shape(sa, dir);
845 }
846
847 /* draw screen area darker with arrow (visualisation of future joining) */
848 static void scrarea_draw_shape_dark(ScrArea *sa, char dir)
849 {
850         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
851         glEnable(GL_BLEND);
852         glColor4ub(0, 0, 0, 50);
853         draw_join_shape(sa, dir);
854         glDisable(GL_BLEND);
855 }
856
857 /* draw screen area ligher with arrow shape ("eraser" of previous dark shape) */
858 static void scrarea_draw_shape_light(ScrArea *sa, char dir)
859 {
860         glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA);
861         glEnable(GL_BLEND);
862         /* value 181 was hardly computed: 181~105 */
863         glColor4ub(255, 255, 255, 50);          
864         /* draw_join_shape(sa, dir); */
865         glRecti(sa->v1->vec.x, sa->v1->vec.y, sa->v3->vec.x, sa->v3->vec.y);
866         glDisable(GL_BLEND);
867 }
868
869 /** screen edges drawing **/
870 static void drawscredge_area(ScrArea *sa)
871 {
872         short x1= sa->v1->vec.x;
873         short y1= sa->v1->vec.y;
874         short x2= sa->v3->vec.x;
875         short y2= sa->v3->vec.y;
876         
877         cpack(0x0);
878         
879         /* right border area */
880         sdrawline(x2, y1, x2, y2);
881         
882         /* left border area */
883         if(x1>0) { /* otherwise it draws the emboss of window over */
884                 sdrawline(x1, y1, x1, y2);
885         }
886         
887         /* top border area */
888         sdrawline(x1, y2, x2, y2);
889         
890         /* bottom border area */
891         sdrawline(x1, y1, x2, y1);
892         
893 }
894
895 /* ****************** EXPORTED API TO OTHER MODULES *************************** */
896
897 bScreen *ED_screen_duplicate(wmWindow *win, bScreen *sc)
898 {
899         bScreen *newsc;
900         
901         if(sc->full != SCREENNORMAL) return NULL; /* XXX handle this case! */
902         
903         /* make new empty screen: */
904         newsc= screen_add(win, sc->scene, sc->id.name+2);
905         /* copy all data */
906         screen_copy(newsc, sc);
907         /* set in window */
908         win->screen= newsc;
909         
910         return newsc;
911 }
912
913 /* screen sets cursor based on swinid */
914 static void region_cursor_set(wmWindow *win, int swinid)
915 {
916         ScrArea *sa= win->screen->areabase.first;
917         
918         for(;sa; sa= sa->next) {
919                 ARegion *ar= sa->regionbase.first;
920                 for(;ar; ar= ar->next) {
921                         if(ar->swinid == swinid) {
922                                 if(ar->type && ar->type->cursor)
923                                         ar->type->cursor(win, sa, ar);
924                                 else
925                                         WM_cursor_set(win, CURSOR_STD);
926                                 return;
927                         }
928                 }
929         }
930 }
931
932 void ED_screen_do_listen(wmWindow *win, wmNotifier *note)
933 {
934         
935         /* generic notes */
936         switch(note->category) {
937                 case NC_WM:
938                         if(note->data==ND_FILEREAD)
939                                 win->screen->do_draw= 1;
940                         break;
941                 case NC_WINDOW:
942                         win->screen->do_draw= 1;
943                         break;
944                 case NC_SCREEN:
945                         if(note->action==NA_EDITED)
946                                 win->screen->do_draw= win->screen->do_refresh= 1;
947                 case NC_SCENE:
948                         if(note->data==ND_MODE)
949                                 region_cursor_set(win, note->swinid);                           
950                         break;
951         }
952 }
953
954 /* only for edge lines between areas, and the blended join arrows */
955 void ED_screen_draw(wmWindow *win)
956 {
957         ScrArea *sa;
958         ScrArea *sa1=NULL;
959         ScrArea *sa2=NULL;
960         int dir = -1;
961         int dira = -1;
962
963         wmSubWindowSet(win, win->screen->mainwin);
964         
965         for(sa= win->screen->areabase.first; sa; sa= sa->next) {
966                 if (sa->flag & AREA_FLAG_DRAWJOINFROM) sa1 = sa;
967                 if (sa->flag & AREA_FLAG_DRAWJOINTO) sa2 = sa;
968                 drawscredge_area(sa);
969         }
970
971         /* blended join arrow */
972         if (sa1 && sa2) {
973                 dir = area_getorientation(win->screen, sa1, sa2);
974                 if (dir >= 0) {
975                         switch(dir) {
976                                 case 0: /* W */
977                                         dir = 'r';
978                                         dira = 'l';
979                                         break;
980                                 case 1: /* N */
981                                         dir = 'd';
982                                         dira = 'u';
983                                         break;
984                                 case 2: /* E */
985                                         dir = 'l';
986                                         dira = 'r';
987                                         break;
988                                 case 3: /* S */
989                                         dir = 'u';
990                                         dira = 'd';
991                                         break;
992                         }
993                 }
994                 scrarea_draw_shape_dark(sa2, dir);
995                 scrarea_draw_shape_light(sa1, dira);
996         }
997         
998 //      if(G.f & G_DEBUG) printf("draw screen\n");
999         win->screen->do_draw= 0;
1000 }
1001
1002 /* make this screen usable */
1003 /* for file read and first use, for scaling window, area moves */
1004 void ED_screen_refresh(wmWindowManager *wm, wmWindow *win)
1005 {
1006         ScrArea *sa;
1007         rcti winrct= {0, win->sizex-1, 0, win->sizey-1};
1008         
1009         screen_test_scale(win->screen, win->sizex, win->sizey);
1010         
1011         if(win->screen->mainwin==0)
1012                 win->screen->mainwin= wm_subwindow_open(win, &winrct);
1013         else
1014                 wm_subwindow_position(win, win->screen->mainwin, &winrct);
1015         
1016         for(sa= win->screen->areabase.first; sa; sa= sa->next) {
1017                 /* set spacetype and region callbacks, calls init() */
1018                 /* sets subwindows for regions, adds handlers */
1019                 ED_area_initialize(wm, win, sa);
1020         }
1021
1022         /* wake up animtimer */
1023         if(win->screen->animtimer)
1024                 WM_event_window_timer_sleep(win, win->screen->animtimer, 0);
1025         
1026         if(G.f & G_DEBUG) printf("set screen\n");
1027         win->screen->do_refresh= 0;
1028
1029         win->screen->context= ed_screen_context;
1030 }
1031
1032 /* file read, set all screens, ... */
1033 void ED_screens_initialize(wmWindowManager *wm)
1034 {
1035         wmWindow *win;
1036         
1037         for(win= wm->windows.first; win; win= win->next) {
1038                 
1039                 if(win->screen==NULL)
1040                         win->screen= G.main->screen.first;
1041                 
1042                 ED_screen_refresh(wm, win);
1043         }
1044 }
1045
1046
1047 /* *********** exit calls are for closing running stuff ******** */
1048
1049 void ED_region_exit(bContext *C, ARegion *ar)
1050 {
1051         ARegion *prevar= CTX_wm_region(C);
1052
1053         CTX_wm_region_set(C, ar);
1054         WM_event_remove_handlers(C, &ar->handlers);
1055         if(ar->swinid)
1056                 wm_subwindow_close(CTX_wm_window(C), ar->swinid);
1057         ar->swinid= 0;
1058         
1059         if(ar->headerstr)
1060                 MEM_freeN(ar->headerstr);
1061         ar->headerstr= NULL;
1062         
1063         CTX_wm_region_set(C, prevar);
1064 }
1065
1066 void ED_area_exit(bContext *C, ScrArea *sa)
1067 {
1068         ScrArea *prevsa= CTX_wm_area(C);
1069         ARegion *ar;
1070
1071         CTX_wm_area_set(C, sa);
1072         for(ar= sa->regionbase.first; ar; ar= ar->next)
1073                 ED_region_exit(C, ar);
1074
1075         WM_event_remove_handlers(C, &sa->handlers);
1076         CTX_wm_area_set(C, prevsa);
1077 }
1078
1079 void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
1080 {
1081         wmWindow *prevwin= CTX_wm_window(C);
1082         ScrArea *sa;
1083         ARegion *ar;
1084
1085         CTX_wm_window_set(C, window);
1086         
1087         if(screen->animtimer)
1088                 WM_event_remove_window_timer(window, screen->animtimer);
1089         screen->animtimer= NULL;
1090         
1091         for(ar= screen->regionbase.first; ar; ar= ar->next)
1092                 ED_region_exit(C, ar);
1093
1094         for(sa= screen->areabase.first; sa; sa= sa->next)
1095                 ED_area_exit(C, sa);
1096
1097         CTX_wm_window_set(C, prevwin);
1098 }
1099
1100 /* *********************************** */
1101
1102 /* case when on area-edge or in azones, or outside window */
1103 static void screen_cursor_set(wmWindow *win, wmEvent *event)
1104 {
1105         ScrArea *sa;
1106         
1107         for(sa= win->screen->areabase.first; sa; sa= sa->next)
1108                 if(is_in_area_actionzone(sa, event->x, event->y))
1109                         break;
1110         
1111         if(sa) {
1112                 WM_cursor_set(win, CURSOR_EDIT);
1113         }
1114         else {
1115                 ScrEdge *actedge= screen_find_active_scredge(win->screen, event->x, event->y);
1116                 
1117                 if (actedge) {
1118                         if(scredge_is_horizontal(actedge))
1119                                 WM_cursor_set(win, CURSOR_Y_MOVE);
1120                         else
1121                                 WM_cursor_set(win, CURSOR_X_MOVE);
1122                 }
1123                 else
1124                         WM_cursor_set(win, CURSOR_STD);
1125         } 
1126 }
1127
1128
1129 /* called in wm_event_system.c. sets state vars in screen, cursors */
1130 /* event type is mouse move */
1131 void ED_screen_set_subwinactive(wmWindow *win, wmEvent *event)
1132 {
1133         if(win->screen) {
1134                 bScreen *scr= win->screen;
1135                 ScrArea *sa;
1136                 ARegion *ar;
1137                 int oldswin= scr->subwinactive;
1138
1139                 for(sa= scr->areabase.first; sa; sa= sa->next) {
1140                         if(event->x > sa->totrct.xmin && event->x < sa->totrct.xmax)
1141                                 if(event->y > sa->totrct.ymin && event->y < sa->totrct.ymax)
1142                                         if(NULL==is_in_area_actionzone(sa, event->x, event->y))
1143                                                 break;
1144                 }
1145                 if(sa) {
1146                         for(ar= sa->regionbase.first; ar; ar= ar->next) {
1147                                 if(BLI_in_rcti(&ar->winrct, event->x, event->y))
1148                                         scr->subwinactive= ar->swinid;
1149                         }
1150                 }
1151                 else
1152                         scr->subwinactive= scr->mainwin;
1153                 
1154                 /* check for redraw headers */
1155                 if(oldswin!=scr->subwinactive) {
1156
1157                         for(sa= scr->areabase.first; sa; sa= sa->next) {
1158                                 int do_draw= 0;
1159                                 
1160                                 for(ar= sa->regionbase.first; ar; ar= ar->next)
1161                                         if(ar->swinid==oldswin || ar->swinid==scr->subwinactive)
1162                                                 do_draw= 1;
1163                                 
1164                                 if(do_draw) {
1165                                         for(ar= sa->regionbase.first; ar; ar= ar->next)
1166                                                 if(ar->regiontype==RGN_TYPE_HEADER)
1167                                                         ED_region_tag_redraw(ar);
1168                                 }
1169                         }
1170                 }
1171                 
1172                 /* cursors, for time being set always on edges, otherwise aregion doesnt switch */
1173                 if(scr->subwinactive==scr->mainwin) {
1174                         screen_cursor_set(win, event);
1175                 }
1176                 else if(oldswin!=scr->subwinactive) {
1177                         region_cursor_set(win, scr->subwinactive);
1178                 }
1179         }
1180 }
1181
1182 int ED_screen_area_active(const bContext *C)
1183 {
1184         bScreen *sc= CTX_wm_screen(C);
1185         ScrArea *sa= CTX_wm_area(C);
1186
1187         if(sc && sa) {
1188                 ARegion *ar;
1189                 for(ar= sa->regionbase.first; ar; ar= ar->next)
1190                         if(ar->swinid == sc->subwinactive)
1191                                 return 1;
1192         }       
1193         return 0;
1194 }
1195
1196 /* operator call, WM + Window + screen already existed before */
1197 /* Do NOT call in area/region queues! */
1198 void ed_screen_set(bContext *C, bScreen *sc)
1199 {
1200         bScreen *oldscreen= CTX_wm_screen(C);
1201         
1202         if(sc->full) {                          /* find associated full */
1203                 bScreen *sc1;
1204                 for(sc1= G.main->screen.first; sc1; sc1= sc1->id.next) {
1205                         ScrArea *sa= sc1->areabase.first;
1206                         if(sa->full==sc) {
1207                                 sc= sc1;
1208                                 break;
1209                         }
1210                 }
1211                 if(sc1==NULL) printf("set screen error\n");
1212         }
1213         
1214         if (oldscreen != sc) {
1215                 wmWindow *win= CTX_wm_window(C);
1216                 wmTimer *wt= oldscreen->animtimer;
1217                 
1218                 /* we put timer to sleep, so screen_exit has to think there's no timer */
1219                 oldscreen->animtimer= NULL;
1220                 if(wt)
1221                         WM_event_window_timer_sleep(win, wt, 1);
1222                 
1223                 ED_screen_exit(C, win, oldscreen);
1224                 oldscreen->animtimer= wt;
1225                 
1226                 win->screen= sc;
1227                 CTX_wm_window_set(C, win);      // stores C->wm.screen... hrmf
1228                 
1229                 ED_screen_refresh(CTX_wm_manager(C), CTX_wm_window(C));
1230                 WM_event_add_notifier(C, NC_WINDOW, NULL);
1231         }
1232 }
1233
1234 /* this function toggles: if area is full then the parent will be restored */
1235 void ed_screen_fullarea(bContext *C, ScrArea *sa)
1236 {
1237         bScreen *sc, *oldscreen;
1238         
1239         if(sa==NULL) {
1240                 return;
1241         }
1242         else if(sa->full) {
1243                 short fulltype;
1244                 
1245                 sc= sa->full;           /* the old screen to restore */
1246                 oldscreen= CTX_wm_screen(C);    /* the one disappearing */
1247                 
1248                 fulltype = sc->full;
1249                 
1250                 /* refuse to go out of SCREENAUTOPLAY as long as G_FLAGS_AUTOPLAY
1251                    is set */
1252                 
1253                 if (fulltype != SCREENAUTOPLAY || (G.flags & G_FILE_AUTOPLAY) == 0) {
1254                         ScrArea *old;
1255                         
1256                         sc->full= 0;
1257                         
1258                         /* find old area */
1259                         for(old= sc->areabase.first; old; old= old->next) 
1260                                 if(old->full) break;
1261                         if(old==NULL) {
1262                                 printf("something wrong in areafullscreen\n"); 
1263                                 return;
1264                         }
1265                             // old feature described below (ton)
1266                                 // in autoplay screens the headers are disabled by 
1267                                 // default. So use the old headertype instead
1268                         
1269                         area_copy_data(old, sa, 1);     /*  1 = swap spacelist */
1270                         
1271                         old->full= NULL;
1272                         
1273                         /* animtimer back */
1274                         sc->animtimer= oldscreen->animtimer;
1275                         oldscreen->animtimer= NULL;
1276                         
1277                         ed_screen_set(C, sc);
1278                         
1279                         free_screen(oldscreen);
1280                         free_libblock(&G.main->screen, oldscreen);
1281                 }
1282         }
1283         else {
1284                 ScrArea *newa;
1285                 
1286                 oldscreen= CTX_wm_screen(C);
1287
1288                 /* is there only 1 area? */
1289                 if(oldscreen->areabase.first==oldscreen->areabase.last) return;
1290                 if(sa->spacetype==SPACE_INFO) return;
1291                 
1292                 oldscreen->full = SCREENFULL;
1293                 
1294                 sc= screen_add(CTX_wm_window(C), CTX_data_scene(C), "temp");
1295                 
1296                 /* timer */
1297                 sc->animtimer= oldscreen->animtimer;
1298                 oldscreen->animtimer= NULL;
1299                 
1300                 /* returns the top small area */
1301                 newa= area_split(CTX_wm_window(C), sc, (ScrArea *)sc->areabase.first, 'h', 0.99f);
1302                 ED_area_newspace(C, newa, SPACE_INFO);
1303
1304                 /* copy area */
1305                 newa= newa->prev;
1306                 area_copy_data(newa, sa, 1);    /* 1 = swap spacelist */
1307
1308                 sa->full= oldscreen;
1309                 newa->full= oldscreen;
1310                 newa->next->full= oldscreen;
1311
1312                 ed_screen_set(C, sc);
1313         }
1314
1315         /* XXX bad code: setscreen() ends with first area active. fullscreen render assumes this too */
1316         CTX_wm_area_set(C, sc->areabase.first);
1317
1318         /* XXX retopo_force_update(); */
1319
1320 }
1321
1322 void ED_screen_full_newspace(bContext *C, ScrArea *sa, int type)
1323 {
1324         if(sa->full==0)
1325                 ed_screen_fullarea(C, sa);
1326
1327         /* CTX_wm_area(C) is new area */
1328         ED_area_newspace(C, CTX_wm_area(C), type);
1329 }
1330
1331 void ED_screen_full_prevspace(bContext *C)
1332 {
1333         ScrArea *sa= CTX_wm_area(C);
1334         
1335         ED_area_prevspace(C);
1336         
1337         if(sa->full)
1338                 ed_screen_fullarea(C, sa);
1339 }
1340
1341 void ED_screen_animation_timer(bContext *C, int enable)
1342 {
1343         bScreen *screen= CTX_wm_screen(C);
1344         wmWindow *win= CTX_wm_window(C);
1345         Scene *scene= CTX_data_scene(C);
1346         
1347         if(screen->animtimer)
1348                 WM_event_remove_window_timer(win, screen->animtimer);
1349         screen->animtimer= NULL;
1350         
1351         if(enable)
1352                 screen->animtimer= WM_event_add_window_timer(win, TIMER0, (1.0/FPS));
1353 }
1354
1355 unsigned int ED_screen_view3d_layers(bScreen *screen)
1356 {
1357         if(screen) {
1358                 unsigned int layer= screen->scene->lay; /* as minimum this */
1359                 ScrArea *sa;
1360                 
1361                 /* get all used view3d layers */
1362                 for(sa= screen->areabase.first; sa; sa= sa->next) {
1363                         if(sa->spacetype==SPACE_VIEW3D)
1364                                 layer |= ((View3D *)sa->spacedata.first)->lay;
1365                 }
1366                 return layer;
1367         }
1368         return 0;
1369 }
1370
1371
1372 /* results in fully updated anim system */
1373 /* in future sound should be on WM level, only 1 sound can play! */
1374 void ED_update_for_newframe(const bContext *C, int mute)
1375 {
1376         bScreen *screen= CTX_wm_screen(C);
1377         Scene *scene= screen->scene;
1378         
1379         //extern void audiostream_scrub(unsigned int frame);    /* seqaudio.c */
1380         
1381         /* this function applies the changes too */
1382         /* XXX future: do all windows */
1383         scene_update_for_newframe(scene, ED_screen_view3d_layers(screen)); /* BKE_scene.h */
1384         
1385         //if ( (CFRA>1) && (!mute) && (scene->audio.flag & AUDIO_SCRUB)) 
1386         //      audiostream_scrub( CFRA );
1387         
1388         /* 3d window, preview */
1389         //BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
1390         
1391         /* all movie/sequence images */
1392         //BIF_image_update_frame();
1393         
1394         /* composite */
1395         if(scene->use_nodes && scene->nodetree)
1396                 ntreeCompositTagAnimated(scene->nodetree);
1397         
1398         /* update animated texture nodes */
1399         {
1400                 Tex *tex;
1401                 for(tex= G.main->tex.first; tex; tex= tex->id.next)
1402                         if( tex->use_nodes && tex->nodetree ) {
1403                                 ntreeTexTagAnimated( tex->nodetree );
1404                         }
1405         }
1406 }
1407
1408