800a618e89e7c69d06038249127953562e3a30dd
[blender-staging.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         sc->winid= win->winid;
415         
416         sv1= screen_addvert(sc, 0, 0);
417         sv2= screen_addvert(sc, 0, win->sizey-1);
418         sv3= screen_addvert(sc, win->sizex-1, win->sizey-1);
419         sv4= screen_addvert(sc, win->sizex-1, 0);
420         
421         screen_addedge(sc, sv1, sv2);
422         screen_addedge(sc, sv2, sv3);
423         screen_addedge(sc, sv3, sv4);
424         screen_addedge(sc, sv4, sv1);
425         
426         /* dummy type, no spacedata */
427         screen_addarea(sc, sv1, sv2, sv3, sv4, HEADERDOWN, SPACE_EMPTY);
428                 
429         return sc;
430 }
431
432 static void screen_copy(bScreen *to, bScreen *from)
433 {
434         ScrVert *s1, *s2;
435         ScrEdge *se;
436         ScrArea *sa, *saf;
437         
438         /* free contents of 'to', is from blenkernel screen.c */
439         free_screen(to);
440         
441         BLI_duplicatelist(&to->vertbase, &from->vertbase);
442         BLI_duplicatelist(&to->edgebase, &from->edgebase);
443         BLI_duplicatelist(&to->areabase, &from->areabase);
444         to->regionbase.first= to->regionbase.last= NULL;
445         
446         s2= to->vertbase.first;
447         for(s1= from->vertbase.first; s1; s1= s1->next, s2= s2->next) {
448                 s1->newv= s2;
449         }
450         
451         for(se= to->edgebase.first; se; se= se->next) {
452                 se->v1= se->v1->newv;
453                 se->v2= se->v2->newv;
454                 sortscrvert(&(se->v1), &(se->v2));
455         }
456         
457         saf= from->areabase.first;
458         for(sa= to->areabase.first; sa; sa= sa->next, saf= saf->next) {
459                 sa->v1= sa->v1->newv;
460                 sa->v2= sa->v2->newv;
461                 sa->v3= sa->v3->newv;
462                 sa->v4= sa->v4->newv;
463                 
464                 sa->spacedata.first= sa->spacedata.last= NULL;
465                 sa->regionbase.first= sa->regionbase.last= NULL;
466                 sa->actionzones.first= sa->actionzones.last= NULL;
467                 sa->scriptlink.totscript= 0;
468                 
469                 area_copy_data(sa, saf, 0);
470         }
471         
472         /* put at zero (needed?) */
473         for(s1= from->vertbase.first; s1; s1= s1->next)
474                 s1->newv= NULL;
475
476 }
477
478
479 /* with sa as center, sb is located at: 0=W, 1=N, 2=E, 3=S */
480 /* -1 = not valid check */
481 /* used with join operator */
482 int area_getorientation(bScreen *screen, ScrArea *sa, ScrArea *sb)
483 {
484         ScrVert *sav1, *sav2, *sav3, *sav4;
485         ScrVert *sbv1, *sbv2, *sbv3, *sbv4;
486
487         if(sa==NULL || sb==NULL) return -1;
488
489         sav1= sa->v1;
490         sav2= sa->v2;
491         sav3= sa->v3;
492         sav4= sa->v4;
493         sbv1= sb->v1;
494         sbv2= sb->v2;
495         sbv3= sb->v3;
496         sbv4= sb->v4;
497         
498         if(sav1==sbv4 && sav2==sbv3) { /* sa to right of sb = W */
499                 return 0;
500         }
501         else if(sav2==sbv1 && sav3==sbv4) { /* sa to bottom of sb = N */
502                 return 1;
503         }
504         else if(sav3==sbv2 && sav4==sbv1) { /* sa to left of sb = E */
505                 return 2;
506         }
507         else if(sav1==sbv2 && sav4==sbv3) { /* sa on top of sb = S*/
508                 return 3;
509         }
510         
511         return -1;
512 }
513
514 /* Helper function to join 2 areas, it has a return value, 0=failed 1=success
515 *       used by the split, join operators
516 */
517 int screen_area_join(bContext *C, bScreen* scr, ScrArea *sa1, ScrArea *sa2) 
518 {
519         int dir;
520         
521         dir = area_getorientation(scr, sa1, sa2);
522         /*printf("dir is : %i \n", dir);*/
523         
524         if (dir < 0)
525         {
526                 if (sa1 ) sa1->flag &= ~AREA_FLAG_DRAWJOINFROM;
527                 if (sa2 ) sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
528                 return 0;
529         }
530         
531         if(dir == 0) {
532                 sa1->v1= sa2->v1;
533                 sa1->v2= sa2->v2;
534                 screen_addedge(scr, sa1->v2, sa1->v3);
535                 screen_addedge(scr, sa1->v1, sa1->v4);
536         }
537         else if(dir == 1) {
538                 sa1->v2= sa2->v2;
539                 sa1->v3= sa2->v3;
540                 screen_addedge(scr, sa1->v1, sa1->v2);
541                 screen_addedge(scr, sa1->v3, sa1->v4);
542         }
543         else if(dir == 2) {
544                 sa1->v3= sa2->v3;
545                 sa1->v4= sa2->v4;
546                 screen_addedge(scr, sa1->v2, sa1->v3);
547                 screen_addedge(scr, sa1->v1, sa1->v4);
548         }
549         else if(dir == 3) {
550                 sa1->v1= sa2->v1;
551                 sa1->v4= sa2->v4;
552                 screen_addedge(scr, sa1->v1, sa1->v2);
553                 screen_addedge(scr, sa1->v3, sa1->v4);
554         }
555         
556         screen_delarea(C, scr, sa2);
557         removedouble_scrverts(scr);
558         sa1->flag &= ~AREA_FLAG_DRAWJOINFROM;
559         
560         return 1;
561 }
562
563 void select_connected_scredge(bScreen *sc, ScrEdge *edge)
564 {
565         ScrEdge *se;
566         ScrVert *sv;
567         int oneselected;
568         char dir;
569         
570         /* select connected, only in the right direction */
571         /* 'dir' is the direction of EDGE */
572         
573         if(edge->v1->vec.x==edge->v2->vec.x) dir= 'v';
574         else dir= 'h';
575         
576         sv= sc->vertbase.first;
577         while(sv) {
578                 sv->flag = 0;
579                 sv= sv->next;
580         }
581         
582         edge->v1->flag= 1;
583         edge->v2->flag= 1;
584         
585         oneselected= 1;
586         while(oneselected) {
587                 se= sc->edgebase.first;
588                 oneselected= 0;
589                 while(se) {
590                         if(se->v1->flag + se->v2->flag==1) {
591                                 if(dir=='h') if(se->v1->vec.y==se->v2->vec.y) {
592                                         se->v1->flag= se->v2->flag= 1;
593                                         oneselected= 1;
594                                 }
595                                         if(dir=='v') if(se->v1->vec.x==se->v2->vec.x) {
596                                                 se->v1->flag= se->v2->flag= 1;
597                                                 oneselected= 1;
598                                         }
599                         }
600                                 se= se->next;
601                 }
602         }
603 }
604
605 /* test if screen vertices should be scaled */
606 static void screen_test_scale(bScreen *sc, int winsizex, int winsizey)
607 {
608         ScrVert *sv=NULL;
609         ScrArea *sa;
610         int sizex, sizey;
611         float facx, facy, tempf, min[2], max[2];
612         
613         /* calculate size */
614         min[0]= min[1]= 10000.0f;
615         max[0]= max[1]= 0.0f;
616         
617         for(sv= sc->vertbase.first; sv; sv= sv->next) {
618                 min[0]= MIN2(min[0], sv->vec.x);
619                 min[1]= MIN2(min[1], sv->vec.y);
620                 max[0]= MAX2(max[0], sv->vec.x);
621                 max[1]= MAX2(max[1], sv->vec.y);
622         }
623         
624         /* always make 0.0 left under */
625         for(sv= sc->vertbase.first; sv; sv= sv->next) {
626                 sv->vec.x -= min[0];
627                 sv->vec.y -= min[1];
628         }
629         
630         sizex= max[0]-min[0];
631         sizey= max[1]-min[1];
632         
633         if(sizex!= winsizex || sizey!= winsizey) {
634                 facx= winsizex;
635                 facx/= (float)sizex;
636                 facy= winsizey;
637                 facy/= (float)sizey;
638                 
639                 /* make sure it fits! */
640                 for(sv= sc->vertbase.first; sv; sv= sv->next) {
641                         tempf= ((float)sv->vec.x)*facx;
642                         sv->vec.x= (short)(tempf+0.5);
643                         sv->vec.x+= AREAGRID-1;
644                         sv->vec.x-=  (sv->vec.x % AREAGRID); 
645                         
646                         CLAMP(sv->vec.x, 0, winsizex);
647                         
648                         tempf= ((float)sv->vec.y )*facy;
649                         sv->vec.y= (short)(tempf+0.5);
650                         sv->vec.y+= AREAGRID-1;
651                         sv->vec.y-=  (sv->vec.y % AREAGRID); 
652                         
653                         CLAMP(sv->vec.y, 0, winsizey);
654                 }
655         }
656         
657         /* test for collapsed areas. This could happen in some blender version... */
658         /* ton: removed option now, it needs Context... */
659         
660         /* make each window at least HEADERY high */
661         for(sa= sc->areabase.first; sa; sa= sa->next) {
662                 int headery= HEADERY+1;
663                 
664                 if(sa->v1->vec.y+headery > sa->v2->vec.y) {
665                         /* lower edge */
666                         ScrEdge *se= screen_findedge(sc, sa->v4, sa->v1);
667                         if(se && sa->v1!=sa->v2 ) {
668                                 int yval;
669                                 
670                                 select_connected_scredge(sc, se);
671                                 
672                                 /* all selected vertices get the right offset */
673                                 yval= sa->v2->vec.y-headery;
674                                 sv= sc->vertbase.first;
675                                 while(sv) {
676                                         /* if is a collapsed area */
677                                         if(sv!=sa->v2 && sv!=sa->v3) {
678                                                 if(sv->flag) sv->vec.y= yval;
679                                         }
680                                         sv= sv->next;
681                                 }
682                         }
683                 }
684         }
685         
686 }
687
688 /* *********************** DRAWING **************************************** */
689
690
691 #define SCR_BACK 0.55
692 #define SCR_ROUND 12
693
694 /* draw vertical shape visualising future joining (left as well
695  * right direction of future joining) */
696 static void draw_horizontal_join_shape(ScrArea *sa, char dir)
697 {
698         vec2f points[10];
699         short i;
700         float w, h;
701         float width = sa->v3->vec.x - sa->v1->vec.x;
702         float height = sa->v3->vec.y - sa->v1->vec.y;
703
704         if(height<width) {
705                 h = height/8;
706                 w = height/4;
707         }
708         else {
709                 h = width/8;
710                 w = width/4;
711         }
712
713         points[0].x = sa->v1->vec.x;
714         points[0].y = sa->v1->vec.y + height/2;
715
716         points[1].x = sa->v1->vec.x;
717         points[1].y = sa->v1->vec.y;
718
719         points[2].x = sa->v4->vec.x - w;
720         points[2].y = sa->v4->vec.y;
721
722         points[3].x = sa->v4->vec.x - w;
723         points[3].y = sa->v4->vec.y + height/2 - 2*h;
724
725         points[4].x = sa->v4->vec.x - 2*w;
726         points[4].y = sa->v4->vec.y + height/2;
727
728         points[5].x = sa->v4->vec.x - w;
729         points[5].y = sa->v4->vec.y + height/2 + 2*h;
730
731         points[6].x = sa->v3->vec.x - w;
732         points[6].y = sa->v3->vec.y;
733
734         points[7].x = sa->v2->vec.x;
735         points[7].y = sa->v2->vec.y;
736
737         points[8].x = sa->v4->vec.x;
738         points[8].y = sa->v4->vec.y + height/2 - h;
739
740         points[9].x = sa->v4->vec.x;
741         points[9].y = sa->v4->vec.y + height/2 + h;
742
743         if(dir=='l') {
744                 /* when direction is left, then we flip direction of arrow */
745                 float cx = sa->v1->vec.x + width;
746                 for(i=0;i<10;i++) {
747                         points[i].x -= cx;
748                         points[i].x = -points[i].x;
749                         points[i].x += sa->v1->vec.x;
750                 }
751         }
752
753         glBegin(GL_POLYGON);
754         for(i=0;i<5;i++)
755                 glVertex2f(points[i].x, points[i].y);
756         glEnd();
757         glBegin(GL_POLYGON);
758         for(i=4;i<8;i++)
759                 glVertex2f(points[i].x, points[i].y);
760         glVertex2f(points[0].x, points[0].y);
761         glEnd();
762
763         glRectf(points[2].x, points[2].y, points[8].x, points[8].y);
764         glRectf(points[6].x, points[6].y, points[9].x, points[9].y);
765 }
766
767 /* draw vertical shape visualising future joining (up/down direction) */
768 static void draw_vertical_join_shape(ScrArea *sa, char dir)
769 {
770         vec2f points[10];
771         short i;
772         float w, h;
773         float width = sa->v3->vec.x - sa->v1->vec.x;
774         float height = sa->v3->vec.y - sa->v1->vec.y;
775
776         if(height<width) {
777                 h = height/4;
778                 w = height/8;
779         }
780         else {
781                 h = width/4;
782                 w = width/8;
783         }
784
785         points[0].x = sa->v1->vec.x + width/2;
786         points[0].y = sa->v3->vec.y;
787
788         points[1].x = sa->v2->vec.x;
789         points[1].y = sa->v2->vec.y;
790
791         points[2].x = sa->v1->vec.x;
792         points[2].y = sa->v1->vec.y + h;
793
794         points[3].x = sa->v1->vec.x + width/2 - 2*w;
795         points[3].y = sa->v1->vec.y + h;
796
797         points[4].x = sa->v1->vec.x + width/2;
798         points[4].y = sa->v1->vec.y + 2*h;
799
800         points[5].x = sa->v1->vec.x + width/2 + 2*w;
801         points[5].y = sa->v1->vec.y + h;
802
803         points[6].x = sa->v4->vec.x;
804         points[6].y = sa->v4->vec.y + h;
805         
806         points[7].x = sa->v3->vec.x;
807         points[7].y = sa->v3->vec.y;
808
809         points[8].x = sa->v1->vec.x + width/2 - w;
810         points[8].y = sa->v1->vec.y;
811
812         points[9].x = sa->v1->vec.x + width/2 + w;
813         points[9].y = sa->v1->vec.y;
814
815         if(dir=='u') {
816                 /* when direction is up, then we flip direction of arrow */
817                 float cy = sa->v1->vec.y + height;
818                 for(i=0;i<10;i++) {
819                         points[i].y -= cy;
820                         points[i].y = -points[i].y;
821                         points[i].y += sa->v1->vec.y;
822                 }
823         }
824
825         glBegin(GL_POLYGON);
826         for(i=0;i<5;i++)
827                 glVertex2f(points[i].x, points[i].y);
828         glEnd();
829         glBegin(GL_POLYGON);
830         for(i=4;i<8;i++)
831                 glVertex2f(points[i].x, points[i].y);
832         glVertex2f(points[0].x, points[0].y);
833         glEnd();
834
835         glRectf(points[2].x, points[2].y, points[8].x, points[8].y);
836         glRectf(points[6].x, points[6].y, points[9].x, points[9].y);
837 }
838
839 /* draw join shape due to direction of joining */
840 static void draw_join_shape(ScrArea *sa, char dir)
841 {
842         if(dir=='u' || dir=='d')
843                 draw_vertical_join_shape(sa, dir);
844         else
845                 draw_horizontal_join_shape(sa, dir);
846 }
847
848 /* draw screen area darker with arrow (visualisation of future joining) */
849 static void scrarea_draw_shape_dark(ScrArea *sa, char dir)
850 {
851         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
852         glEnable(GL_BLEND);
853         glColor4ub(0, 0, 0, 50);
854         draw_join_shape(sa, dir);
855         glDisable(GL_BLEND);
856 }
857
858 /* draw screen area ligher with arrow shape ("eraser" of previous dark shape) */
859 static void scrarea_draw_shape_light(ScrArea *sa, char dir)
860 {
861         glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA);
862         glEnable(GL_BLEND);
863         /* value 181 was hardly computed: 181~105 */
864         glColor4ub(255, 255, 255, 50);          
865         /* draw_join_shape(sa, dir); */
866         glRecti(sa->v1->vec.x, sa->v1->vec.y, sa->v3->vec.x, sa->v3->vec.y);
867         glDisable(GL_BLEND);
868 }
869
870 /** screen edges drawing **/
871 static void drawscredge_area(ScrArea *sa)
872 {
873         short x1= sa->v1->vec.x;
874         short y1= sa->v1->vec.y;
875         short x2= sa->v3->vec.x;
876         short y2= sa->v3->vec.y;
877         
878         cpack(0x0);
879         
880         /* right border area */
881         sdrawline(x2, y1, x2, y2);
882         
883         /* left border area */
884         if(x1>0) { /* otherwise it draws the emboss of window over */
885                 sdrawline(x1, y1, x1, y2);
886         }
887         
888         /* top border area */
889         sdrawline(x1, y2, x2, y2);
890         
891         /* bottom border area */
892         sdrawline(x1, y1, x2, y1);
893         
894 }
895
896 /* ****************** EXPORTED API TO OTHER MODULES *************************** */
897
898 bScreen *ED_screen_duplicate(wmWindow *win, bScreen *sc)
899 {
900         bScreen *newsc;
901         
902         if(sc->full != SCREENNORMAL) return NULL; /* XXX handle this case! */
903         
904         /* make new empty screen: */
905         newsc= screen_add(win, sc->scene, sc->id.name+2);
906         /* copy all data */
907         screen_copy(newsc, sc);
908         /* set in window */
909         win->screen= newsc;
910         
911         /* store identifier */
912         win->screen->winid= win->winid;
913         BLI_strncpy(win->screenname, win->screen->id.name+2, 21);
914
915         return newsc;
916 }
917
918 /* screen sets cursor based on swinid */
919 static void region_cursor_set(wmWindow *win, int swinid)
920 {
921         ScrArea *sa= win->screen->areabase.first;
922         
923         for(;sa; sa= sa->next) {
924                 ARegion *ar= sa->regionbase.first;
925                 for(;ar; ar= ar->next) {
926                         if(ar->swinid == swinid) {
927                                 if(ar->type && ar->type->cursor)
928                                         ar->type->cursor(win, sa, ar);
929                                 else
930                                         WM_cursor_set(win, CURSOR_STD);
931                                 return;
932                         }
933                 }
934         }
935 }
936
937 void ED_screen_do_listen(wmWindow *win, wmNotifier *note)
938 {
939         
940         /* generic notes */
941         switch(note->category) {
942                 case NC_WM:
943                         if(note->data==ND_FILEREAD)
944                                 win->screen->do_draw= 1;
945                         break;
946                 case NC_WINDOW:
947                         win->screen->do_draw= 1;
948                         break;
949                 case NC_SCREEN:
950                         if(note->action==NA_EDITED)
951                                 win->screen->do_draw= win->screen->do_refresh= 1;
952                 case NC_SCENE:
953                         if(note->data==ND_MODE)
954                                 region_cursor_set(win, note->swinid);                           
955                         break;
956         }
957 }
958
959 /* only for edge lines between areas, and the blended join arrows */
960 void ED_screen_draw(wmWindow *win)
961 {
962         ScrArea *sa;
963         ScrArea *sa1=NULL;
964         ScrArea *sa2=NULL;
965         int dir = -1;
966         int dira = -1;
967
968         wmSubWindowSet(win, win->screen->mainwin);
969         
970         for(sa= win->screen->areabase.first; sa; sa= sa->next) {
971                 if (sa->flag & AREA_FLAG_DRAWJOINFROM) sa1 = sa;
972                 if (sa->flag & AREA_FLAG_DRAWJOINTO) sa2 = sa;
973                 drawscredge_area(sa);
974         }
975
976         /* blended join arrow */
977         if (sa1 && sa2) {
978                 dir = area_getorientation(win->screen, sa1, sa2);
979                 if (dir >= 0) {
980                         switch(dir) {
981                                 case 0: /* W */
982                                         dir = 'r';
983                                         dira = 'l';
984                                         break;
985                                 case 1: /* N */
986                                         dir = 'd';
987                                         dira = 'u';
988                                         break;
989                                 case 2: /* E */
990                                         dir = 'l';
991                                         dira = 'r';
992                                         break;
993                                 case 3: /* S */
994                                         dir = 'u';
995                                         dira = 'd';
996                                         break;
997                         }
998                 }
999                 scrarea_draw_shape_dark(sa2, dir);
1000                 scrarea_draw_shape_light(sa1, dira);
1001         }
1002         
1003 //      if(G.f & G_DEBUG) printf("draw screen\n");
1004         win->screen->do_draw= 0;
1005 }
1006
1007 /* make this screen usable */
1008 /* for file read and first use, for scaling window, area moves */
1009 void ED_screen_refresh(wmWindowManager *wm, wmWindow *win)
1010 {
1011         ScrArea *sa;
1012         rcti winrct= {0, win->sizex-1, 0, win->sizey-1};
1013         
1014         screen_test_scale(win->screen, win->sizex, win->sizey);
1015         
1016         if(win->screen->mainwin==0)
1017                 win->screen->mainwin= wm_subwindow_open(win, &winrct);
1018         else
1019                 wm_subwindow_position(win, win->screen->mainwin, &winrct);
1020         
1021         for(sa= win->screen->areabase.first; sa; sa= sa->next) {
1022                 /* set spacetype and region callbacks, calls init() */
1023                 /* sets subwindows for regions, adds handlers */
1024                 ED_area_initialize(wm, win, sa);
1025         }
1026
1027         /* wake up animtimer */
1028         if(win->screen->animtimer)
1029                 WM_event_window_timer_sleep(win, win->screen->animtimer, 0);
1030         
1031         if(G.f & G_DEBUG) printf("set screen\n");
1032         win->screen->do_refresh= 0;
1033
1034         win->screen->context= ed_screen_context;
1035 }
1036
1037 /* file read, set all screens, ... */
1038 void ED_screens_initialize(wmWindowManager *wm)
1039 {
1040         wmWindow *win;
1041         
1042         for(win= wm->windows.first; win; win= win->next) {
1043                 
1044                 if(win->screen==NULL)
1045                         win->screen= G.main->screen.first;
1046                 
1047                 ED_screen_refresh(wm, win);
1048         }
1049 }
1050
1051
1052 /* *********** exit calls are for closing running stuff ******** */
1053
1054 void ED_region_exit(bContext *C, ARegion *ar)
1055 {
1056         ARegion *prevar= CTX_wm_region(C);
1057
1058         CTX_wm_region_set(C, ar);
1059         WM_event_remove_handlers(C, &ar->handlers);
1060         if(ar->swinid)
1061                 wm_subwindow_close(CTX_wm_window(C), ar->swinid);
1062         ar->swinid= 0;
1063         
1064         if(ar->headerstr)
1065                 MEM_freeN(ar->headerstr);
1066         ar->headerstr= NULL;
1067         
1068         CTX_wm_region_set(C, prevar);
1069 }
1070
1071 void ED_area_exit(bContext *C, ScrArea *sa)
1072 {
1073         ScrArea *prevsa= CTX_wm_area(C);
1074         ARegion *ar;
1075
1076         CTX_wm_area_set(C, sa);
1077         for(ar= sa->regionbase.first; ar; ar= ar->next)
1078                 ED_region_exit(C, ar);
1079
1080         WM_event_remove_handlers(C, &sa->handlers);
1081         CTX_wm_area_set(C, prevsa);
1082 }
1083
1084 void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
1085 {
1086         wmWindow *prevwin= CTX_wm_window(C);
1087         ScrArea *sa;
1088         ARegion *ar;
1089
1090         CTX_wm_window_set(C, window);
1091         
1092         if(screen->animtimer)
1093                 WM_event_remove_window_timer(window, screen->animtimer);
1094         screen->animtimer= NULL;
1095         
1096         if(screen->mainwin)
1097                 wm_subwindow_close(window, screen->mainwin);
1098         screen->mainwin= 0;
1099         screen->subwinactive= 0;
1100         
1101         for(ar= screen->regionbase.first; ar; ar= ar->next)
1102                 ED_region_exit(C, ar);
1103
1104         for(sa= screen->areabase.first; sa; sa= sa->next)
1105                 ED_area_exit(C, sa);
1106
1107         /* mark it available for use for other windows */
1108         screen->winid= 0;
1109         
1110         CTX_wm_window_set(C, prevwin);
1111 }
1112
1113 /* *********************************** */
1114
1115 /* case when on area-edge or in azones, or outside window */
1116 static void screen_cursor_set(wmWindow *win, wmEvent *event)
1117 {
1118         ScrArea *sa;
1119         
1120         for(sa= win->screen->areabase.first; sa; sa= sa->next)
1121                 if(is_in_area_actionzone(sa, event->x, event->y))
1122                         break;
1123         
1124         if(sa) {
1125                 WM_cursor_set(win, CURSOR_EDIT);
1126         }
1127         else {
1128                 ScrEdge *actedge= screen_find_active_scredge(win->screen, event->x, event->y);
1129                 
1130                 if (actedge) {
1131                         if(scredge_is_horizontal(actedge))
1132                                 WM_cursor_set(win, CURSOR_Y_MOVE);
1133                         else
1134                                 WM_cursor_set(win, CURSOR_X_MOVE);
1135                 }
1136                 else
1137                         WM_cursor_set(win, CURSOR_STD);
1138         } 
1139 }
1140
1141
1142 /* called in wm_event_system.c. sets state vars in screen, cursors */
1143 /* event type is mouse move */
1144 void ED_screen_set_subwinactive(wmWindow *win, wmEvent *event)
1145 {
1146         if(win->screen) {
1147                 bScreen *scr= win->screen;
1148                 ScrArea *sa;
1149                 ARegion *ar;
1150                 int oldswin= scr->subwinactive;
1151
1152                 for(sa= scr->areabase.first; sa; sa= sa->next) {
1153                         if(event->x > sa->totrct.xmin && event->x < sa->totrct.xmax)
1154                                 if(event->y > sa->totrct.ymin && event->y < sa->totrct.ymax)
1155                                         if(NULL==is_in_area_actionzone(sa, event->x, event->y))
1156                                                 break;
1157                 }
1158                 if(sa) {
1159                         for(ar= sa->regionbase.first; ar; ar= ar->next) {
1160                                 if(BLI_in_rcti(&ar->winrct, event->x, event->y))
1161                                         scr->subwinactive= ar->swinid;
1162                         }
1163                 }
1164                 else
1165                         scr->subwinactive= scr->mainwin;
1166                 
1167                 /* check for redraw headers */
1168                 if(oldswin!=scr->subwinactive) {
1169
1170                         for(sa= scr->areabase.first; sa; sa= sa->next) {
1171                                 int do_draw= 0;
1172                                 
1173                                 for(ar= sa->regionbase.first; ar; ar= ar->next)
1174                                         if(ar->swinid==oldswin || ar->swinid==scr->subwinactive)
1175                                                 do_draw= 1;
1176                                 
1177                                 if(do_draw) {
1178                                         for(ar= sa->regionbase.first; ar; ar= ar->next)
1179                                                 if(ar->regiontype==RGN_TYPE_HEADER)
1180                                                         ED_region_tag_redraw(ar);
1181                                 }
1182                         }
1183                 }
1184                 
1185                 /* cursors, for time being set always on edges, otherwise aregion doesnt switch */
1186                 if(scr->subwinactive==scr->mainwin) {
1187                         screen_cursor_set(win, event);
1188                 }
1189                 else if(oldswin!=scr->subwinactive) {
1190                         region_cursor_set(win, scr->subwinactive);
1191                 }
1192         }
1193 }
1194
1195 int ED_screen_area_active(const bContext *C)
1196 {
1197         bScreen *sc= CTX_wm_screen(C);
1198         ScrArea *sa= CTX_wm_area(C);
1199
1200         if(sc && sa) {
1201                 ARegion *ar;
1202                 for(ar= sa->regionbase.first; ar; ar= ar->next)
1203                         if(ar->swinid == sc->subwinactive)
1204                                 return 1;
1205         }       
1206         return 0;
1207 }
1208
1209 /* operator call, WM + Window + screen already existed before */
1210 /* Do NOT call in area/region queues! */
1211 void ED_screen_set(bContext *C, bScreen *sc)
1212 {
1213         wmWindow *win= CTX_wm_window(C);
1214         bScreen *oldscreen= CTX_wm_screen(C);
1215         ID *id;
1216         
1217         /* validate screen, it's called with notifier reference */
1218         for(id= CTX_data_main(C)->screen.first; id; id= id->next)
1219                 if(sc == (bScreen *)id)
1220                         break;
1221         if(id==NULL) 
1222                 return;
1223         
1224         /* check for valid winid */
1225         if(sc->winid!=0 && sc->winid!=win->winid)
1226                 return;
1227         
1228         if(sc->full) {                          /* find associated full */
1229                 bScreen *sc1;
1230                 for(sc1= CTX_data_main(C)->screen.first; sc1; sc1= sc1->id.next) {
1231                         ScrArea *sa= sc1->areabase.first;
1232                         if(sa->full==sc) {
1233                                 sc= sc1;
1234                                 break;
1235                         }
1236                 }
1237                 if(sc1==NULL) printf("set screen error\n");
1238         }
1239         
1240         if (oldscreen != sc) {
1241                 wmTimer *wt= oldscreen->animtimer;
1242                 
1243                 /* we put timer to sleep, so screen_exit has to think there's no timer */
1244                 oldscreen->animtimer= NULL;
1245                 if(wt)
1246                         WM_event_window_timer_sleep(win, wt, 1);
1247                 
1248                 ED_screen_exit(C, win, oldscreen);
1249                 oldscreen->animtimer= wt;
1250                 
1251                 win->screen= sc;
1252                 CTX_wm_window_set(C, win);      // stores C->wm.screen... hrmf
1253                 
1254                 /* prevent multiwin errors */
1255                 sc->winid= win->winid;
1256                 
1257                 ED_screen_refresh(CTX_wm_manager(C), CTX_wm_window(C));
1258                 WM_event_add_notifier(C, NC_WINDOW, NULL);
1259         }
1260 }
1261
1262 /* this function toggles: if area is full then the parent will be restored */
1263 void ed_screen_fullarea(bContext *C, ScrArea *sa)
1264 {
1265         bScreen *sc, *oldscreen;
1266         
1267         if(sa==NULL) {
1268                 return;
1269         }
1270         else if(sa->full) {
1271                 short fulltype;
1272                 
1273                 sc= sa->full;           /* the old screen to restore */
1274                 oldscreen= CTX_wm_screen(C);    /* the one disappearing */
1275                 
1276                 fulltype = sc->full;
1277                 
1278                 /* refuse to go out of SCREENAUTOPLAY as long as G_FLAGS_AUTOPLAY
1279                    is set */
1280                 
1281                 if (fulltype != SCREENAUTOPLAY || (G.flags & G_FILE_AUTOPLAY) == 0) {
1282                         ScrArea *old;
1283                         
1284                         sc->full= 0;
1285                         
1286                         /* find old area */
1287                         for(old= sc->areabase.first; old; old= old->next) 
1288                                 if(old->full) break;
1289                         if(old==NULL) {
1290                                 printf("something wrong in areafullscreen\n"); 
1291                                 return;
1292                         }
1293                             // old feature described below (ton)
1294                                 // in autoplay screens the headers are disabled by 
1295                                 // default. So use the old headertype instead
1296                         
1297                         area_copy_data(old, sa, 1);     /*  1 = swap spacelist */
1298                         
1299                         old->full= NULL;
1300                         
1301                         /* animtimer back */
1302                         sc->animtimer= oldscreen->animtimer;
1303                         oldscreen->animtimer= NULL;
1304                         
1305                         ED_screen_set(C, sc);
1306                         
1307                         free_screen(oldscreen);
1308                         free_libblock(&G.main->screen, oldscreen);
1309                 }
1310         }
1311         else {
1312                 ScrArea *newa;
1313                 
1314                 oldscreen= CTX_wm_screen(C);
1315
1316                 /* is there only 1 area? */
1317                 if(oldscreen->areabase.first==oldscreen->areabase.last) return;
1318                 if(sa->spacetype==SPACE_INFO) return;
1319                 
1320                 oldscreen->full = SCREENFULL;
1321                 
1322                 sc= screen_add(CTX_wm_window(C), CTX_data_scene(C), "temp");
1323                 sc->full = SCREENFULL; // XXX
1324                 
1325                 /* timer */
1326                 sc->animtimer= oldscreen->animtimer;
1327                 oldscreen->animtimer= NULL;
1328                 
1329                 /* returns the top small area */
1330                 newa= area_split(CTX_wm_window(C), sc, (ScrArea *)sc->areabase.first, 'h', 0.99f);
1331                 ED_area_newspace(C, newa, SPACE_INFO);
1332
1333                 /* copy area */
1334                 newa= newa->prev;
1335                 area_copy_data(newa, sa, 1);    /* 1 = swap spacelist */
1336
1337                 sa->full= oldscreen;
1338                 newa->full= oldscreen;
1339                 newa->next->full= oldscreen; // XXX
1340
1341                 ED_screen_set(C, sc);
1342         }
1343
1344         /* XXX bad code: setscreen() ends with first area active. fullscreen render assumes this too */
1345         CTX_wm_area_set(C, sc->areabase.first);
1346
1347         /* XXX retopo_force_update(); */
1348
1349 }
1350
1351 void ED_screen_full_newspace(bContext *C, ScrArea *sa, int type)
1352 {
1353         if(sa->full==0)
1354                 ed_screen_fullarea(C, sa);
1355
1356         /* CTX_wm_area(C) is new area */
1357         ED_area_newspace(C, CTX_wm_area(C), type);
1358 }
1359
1360 void ED_screen_full_prevspace(bContext *C)
1361 {
1362         ScrArea *sa= CTX_wm_area(C);
1363         
1364         ED_area_prevspace(C);
1365         
1366         if(sa->full)
1367                 ed_screen_fullarea(C, sa);
1368 }
1369
1370 void ED_screen_animation_timer(bContext *C, int enable)
1371 {
1372         bScreen *screen= CTX_wm_screen(C);
1373         wmWindow *win= CTX_wm_window(C);
1374         Scene *scene= CTX_data_scene(C);
1375         
1376         if(screen->animtimer)
1377                 WM_event_remove_window_timer(win, screen->animtimer);
1378         screen->animtimer= NULL;
1379         
1380         if(enable)
1381                 screen->animtimer= WM_event_add_window_timer(win, TIMER0, (1.0/FPS));
1382 }
1383
1384 unsigned int ED_screen_view3d_layers(bScreen *screen)
1385 {
1386         if(screen) {
1387                 unsigned int layer= screen->scene->lay; /* as minimum this */
1388                 ScrArea *sa;
1389                 
1390                 /* get all used view3d layers */
1391                 for(sa= screen->areabase.first; sa; sa= sa->next) {
1392                         if(sa->spacetype==SPACE_VIEW3D)
1393                                 layer |= ((View3D *)sa->spacedata.first)->lay;
1394                 }
1395                 return layer;
1396         }
1397         return 0;
1398 }
1399
1400
1401 /* results in fully updated anim system */
1402 /* in future sound should be on WM level, only 1 sound can play! */
1403 void ED_update_for_newframe(const bContext *C, int mute)
1404 {
1405         bScreen *screen= CTX_wm_screen(C);
1406         Scene *scene= screen->scene;
1407         
1408         //extern void audiostream_scrub(unsigned int frame);    /* seqaudio.c */
1409         
1410         /* this function applies the changes too */
1411         /* XXX future: do all windows */
1412         scene_update_for_newframe(scene, ED_screen_view3d_layers(screen)); /* BKE_scene.h */
1413         
1414         //if ( (CFRA>1) && (!mute) && (scene->audio.flag & AUDIO_SCRUB)) 
1415         //      audiostream_scrub( CFRA );
1416         
1417         /* 3d window, preview */
1418         //BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
1419         
1420         /* all movie/sequence images */
1421         //BIF_image_update_frame();
1422         
1423         /* composite */
1424         if(scene->use_nodes && scene->nodetree)
1425                 ntreeCompositTagAnimated(scene->nodetree);
1426         
1427         /* update animated texture nodes */
1428         {
1429                 Tex *tex;
1430                 for(tex= G.main->tex.first; tex; tex= tex->id.next)
1431                         if( tex->use_nodes && tex->nodetree ) {
1432                                 ntreeTexTagAnimated( tex->nodetree );
1433                         }
1434         }
1435 }
1436
1437