4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2008 Blender Foundation.
21 * All rights reserved.
24 * ***** END GPL LICENSE BLOCK *****
29 #include "MEM_guardedalloc.h"
31 #include "DNA_vec_types.h"
32 #include "DNA_scene_types.h"
33 #include "DNA_screen_types.h"
35 #include "BLI_blenlib.h"
37 #include "BKE_context.h"
38 #include "BKE_global.h"
39 #include "BKE_library.h"
41 #include "BKE_screen.h"
42 #include "BKE_utildefines.h"
45 #include "BIF_glutil.h"
50 #include "ED_screen.h"
51 #include "ED_screen_types.h"
53 #include "wm_subwindow.h"
55 #include "screen_intern.h" /* own module include */
58 /* ******************* screen vert, edge, area managing *********************** */
60 static ScrVert *screen_addvert(bScreen *sc, short x, short y)
62 ScrVert *sv= MEM_callocN(sizeof(ScrVert), "addscrvert");
66 BLI_addtail(&sc->vertbase, sv);
70 static void sortscrvert(ScrVert **v1, ScrVert **v2)
81 static ScrEdge *screen_addedge(bScreen *sc, ScrVert *v1, ScrVert *v2)
83 ScrEdge *se= MEM_callocN(sizeof(ScrEdge), "addscredge");
85 sortscrvert(&v1, &v2);
89 BLI_addtail(&sc->edgebase, se);
94 ScrEdge *screen_findedge(bScreen *sc, ScrVert *v1, ScrVert *v2)
98 sortscrvert(&v1, &v2);
99 for (se= sc->edgebase.first; se; se= se->next)
100 if(se->v1==v1 && se->v2==v2)
106 void removedouble_scrverts(bScreen *sc)
112 verg= sc->vertbase.first;
114 if(verg->newv==NULL) { /* !!! */
117 if(v1->newv==NULL) { /* !?! */
118 if(v1->vec.x==verg->vec.x && v1->vec.y==verg->vec.y) {
119 /* printf("doublevert\n"); */
129 /* replace pointers in edges and faces */
130 se= sc->edgebase.first;
132 if(se->v1->newv) se->v1= se->v1->newv;
133 if(se->v2->newv) se->v2= se->v2->newv;
134 /* edges changed: so.... */
135 sortscrvert(&(se->v1), &(se->v2));
138 sa= sc->areabase.first;
140 if(sa->v1->newv) sa->v1= sa->v1->newv;
141 if(sa->v2->newv) sa->v2= sa->v2->newv;
142 if(sa->v3->newv) sa->v3= sa->v3->newv;
143 if(sa->v4->newv) sa->v4= sa->v4->newv;
148 verg= sc->vertbase.first;
152 BLI_remlink(&sc->vertbase, verg);
160 void removenotused_scrverts(bScreen *sc)
165 /* we assume edges are ok */
167 se= sc->edgebase.first;
174 sv= sc->vertbase.first;
178 BLI_remlink(&sc->vertbase, sv);
186 void removedouble_scredges(bScreen *sc)
188 ScrEdge *verg, *se, *sn;
191 verg= sc->edgebase.first;
196 if(verg->v1==se->v1 && verg->v2==se->v2) {
197 BLI_remlink(&sc->edgebase, se);
206 void removenotused_scredges(bScreen *sc)
212 /* sets flags when edge is used in area */
213 sa= sc->areabase.first;
215 se= screen_findedge(sc, sa->v1, sa->v2);
216 if(se==0) printf("error: area %d edge 1 doesn't exist\n", a);
218 se= screen_findedge(sc, sa->v2, sa->v3);
219 if(se==0) printf("error: area %d edge 2 doesn't exist\n", a);
221 se= screen_findedge(sc, sa->v3, sa->v4);
222 if(se==0) printf("error: area %d edge 3 doesn't exist\n", a);
224 se= screen_findedge(sc, sa->v4, sa->v1);
225 if(se==0) printf("error: area %d edge 4 doesn't exist\n", a);
230 se= sc->edgebase.first;
234 BLI_remlink(&sc->edgebase, se);
242 int scredge_is_horizontal(ScrEdge *se)
244 return (se->v1->vec.y == se->v2->vec.y);
247 ScrEdge *screen_find_active_scredge(bScreen *sc, int mx, int my)
251 for (se= sc->edgebase.first; se; se= se->next) {
252 if (scredge_is_horizontal(se)) {
254 min= MIN2(se->v1->vec.x, se->v2->vec.x);
255 max= MAX2(se->v1->vec.x, se->v2->vec.x);
257 if (abs(my-se->v1->vec.y)<=2 && mx>=min && mx<=max)
262 min= MIN2(se->v1->vec.y, se->v2->vec.y);
263 max= MAX2(se->v1->vec.y, se->v2->vec.y);
265 if (abs(mx-se->v1->vec.x)<=2 && my>=min && my<=max)
275 /* adds no space data */
276 static ScrArea *screen_addarea(bScreen *sc, ScrVert *v1, ScrVert *v2, ScrVert *v3, ScrVert *v4, short headertype, short spacetype)
278 ScrArea *sa= MEM_callocN(sizeof(ScrArea), "addscrarea");
283 sa->headertype= headertype;
284 sa->spacetype= sa->butspacetype= spacetype;
286 BLI_addtail(&sc->areabase, sa);
291 static void screen_delarea(bContext *C, bScreen *sc, ScrArea *sa)
296 BKE_screen_area_free(sa);
298 BLI_remlink(&sc->areabase, sa);
302 /* return 0: no split possible */
303 /* else return (integer) screencoordinate split point */
304 static short testsplitpoint(wmWindow *win, ScrArea *sa, char dir, float fac)
309 if(dir=='v' && (sa->v4->vec.x- sa->v1->vec.x <= 2*AREAMINX)) return 0;
310 if(dir=='h' && (sa->v2->vec.y- sa->v1->vec.y <= 2*AREAMINY)) return 0;
313 if(fac<0.0) fac= 0.0;
314 if(fac>1.0) fac= 1.0;
317 y= sa->v1->vec.y+ fac*(sa->v2->vec.y- sa->v1->vec.y);
319 if(y- sa->v1->vec.y < AREAMINY)
320 y= sa->v1->vec.y+ AREAMINY;
321 else if(sa->v2->vec.y- y < AREAMINY)
322 y= sa->v2->vec.y- AREAMINY;
323 else y-= (y % AREAGRID);
328 x= sa->v1->vec.x+ fac*(sa->v4->vec.x- sa->v1->vec.x);
330 if(x- sa->v1->vec.x < AREAMINX)
331 x= sa->v1->vec.x+ AREAMINX;
332 else if(sa->v4->vec.x- x < AREAMINX)
333 x= sa->v4->vec.x- AREAMINX;
334 else x-= (x % AREAGRID);
340 ScrArea *area_split(wmWindow *win, bScreen *sc, ScrArea *sa, char dir, float fac)
346 if(sa==NULL) return NULL;
348 split= testsplitpoint(win, sa, dir, fac);
349 if(split==0) return NULL;
353 sv1= screen_addvert(sc, sa->v1->vec.x, split);
354 sv2= screen_addvert(sc, sa->v4->vec.x, split);
357 screen_addedge(sc, sa->v1, sv1);
358 screen_addedge(sc, sv1, sa->v2);
359 screen_addedge(sc, sa->v3, sv2);
360 screen_addedge(sc, sv2, sa->v4);
361 screen_addedge(sc, sv1, sv2);
364 newa= screen_addarea(sc, sv1, sa->v2, sa->v3, sv2, sa->headertype, sa->spacetype);
365 area_copy_data(newa, sa, 0);
374 sv1= screen_addvert(sc, split, sa->v1->vec.y);
375 sv2= screen_addvert(sc, split, sa->v2->vec.y);
378 screen_addedge(sc, sa->v1, sv1);
379 screen_addedge(sc, sv1, sa->v4);
380 screen_addedge(sc, sa->v2, sv2);
381 screen_addedge(sc, sv2, sa->v3);
382 screen_addedge(sc, sv1, sv2);
384 /* new areas: left */
385 newa= screen_addarea(sc, sa->v1, sa->v2, sv2, sv1, sa->headertype, sa->spacetype);
386 area_copy_data(newa, sa, 0);
393 /* remove double vertices en edges */
394 removedouble_scrverts(sc);
395 removedouble_scredges(sc);
396 removenotused_scredges(sc);
401 /* empty screen, with 1 dummy area without spacedata */
402 /* uses window size */
403 bScreen *screen_add(wmWindow *win, Scene *scene, char *name)
406 ScrVert *sv1, *sv2, *sv3, *sv4;
408 sc= alloc_libblock(&G.main->screen, ID_SCR, name);
412 sv1= screen_addvert(sc, 0, 0);
413 sv2= screen_addvert(sc, 0, win->sizey-1);
414 sv3= screen_addvert(sc, win->sizex-1, win->sizey-1);
415 sv4= screen_addvert(sc, win->sizex-1, 0);
417 screen_addedge(sc, sv1, sv2);
418 screen_addedge(sc, sv2, sv3);
419 screen_addedge(sc, sv3, sv4);
420 screen_addedge(sc, sv4, sv1);
422 /* dummy type, no spacedata */
423 screen_addarea(sc, sv1, sv2, sv3, sv4, HEADERDOWN, SPACE_EMPTY);
428 static void screen_copy(bScreen *to, bScreen *from)
434 /* free contents of 'to', is from blenkernel screen.c */
437 BLI_duplicatelist(&to->vertbase, &from->vertbase);
438 BLI_duplicatelist(&to->edgebase, &from->edgebase);
439 BLI_duplicatelist(&to->areabase, &from->areabase);
440 to->regionbase.first= to->regionbase.last= NULL;
442 s2= to->vertbase.first;
443 for(s1= from->vertbase.first; s1; s1= s1->next, s2= s2->next) {
447 for(se= to->edgebase.first; se; se= se->next) {
448 se->v1= se->v1->newv;
449 se->v2= se->v2->newv;
450 sortscrvert(&(se->v1), &(se->v2));
453 saf= from->areabase.first;
454 for(sa= to->areabase.first; sa; sa= sa->next, saf= saf->next) {
455 sa->v1= sa->v1->newv;
456 sa->v2= sa->v2->newv;
457 sa->v3= sa->v3->newv;
458 sa->v4= sa->v4->newv;
460 sa->spacedata.first= sa->spacedata.last= NULL;
461 sa->regionbase.first= sa->regionbase.last= NULL;
462 sa->actionzones.first= sa->actionzones.last= NULL;
463 sa->scriptlink.totscript= 0;
465 area_copy_data(sa, saf, 0);
468 /* put at zero (needed?) */
469 for(s1= from->vertbase.first; s1; s1= s1->next)
475 /* with sa as center, sb is located at: 0=W, 1=N, 2=E, 3=S */
476 /* -1 = not valid check */
477 /* used with join operator */
478 int area_getorientation(bScreen *screen, ScrArea *sa, ScrArea *sb)
480 ScrVert *sav1, *sav2, *sav3, *sav4;
481 ScrVert *sbv1, *sbv2, *sbv3, *sbv4;
483 if(sa==NULL || sb==NULL) return -1;
494 if(sav1==sbv4 && sav2==sbv3) { /* sa to right of sb = W */
497 else if(sav2==sbv1 && sav3==sbv4) { /* sa to bottom of sb = N */
500 else if(sav3==sbv2 && sav4==sbv1) { /* sa to left of sb = E */
503 else if(sav1==sbv2 && sav4==sbv3) { /* sa on top of sb = S*/
510 /* Helper function to join 2 areas, it has a return value, 0=failed 1=success
511 * used by the split, join operators
513 int screen_area_join(bContext *C, bScreen* scr, ScrArea *sa1, ScrArea *sa2)
517 dir = area_getorientation(scr, sa1, sa2);
518 /*printf("dir is : %i \n", dir);*/
522 if (sa1 ) sa1->flag &= ~AREA_FLAG_DRAWJOINFROM;
523 if (sa2 ) sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
530 screen_addedge(scr, sa1->v2, sa1->v3);
531 screen_addedge(scr, sa1->v1, sa1->v4);
536 screen_addedge(scr, sa1->v1, sa1->v2);
537 screen_addedge(scr, sa1->v3, sa1->v4);
542 screen_addedge(scr, sa1->v2, sa1->v3);
543 screen_addedge(scr, sa1->v1, sa1->v4);
548 screen_addedge(scr, sa1->v1, sa1->v2);
549 screen_addedge(scr, sa1->v3, sa1->v4);
552 screen_delarea(C, scr, sa2);
553 removedouble_scrverts(scr);
554 sa1->flag &= ~AREA_FLAG_DRAWJOINFROM;
559 void select_connected_scredge(bScreen *sc, ScrEdge *edge)
566 /* select connected, only in the right direction */
567 /* 'dir' is the direction of EDGE */
569 if(edge->v1->vec.x==edge->v2->vec.x) dir= 'v';
572 sv= sc->vertbase.first;
583 se= sc->edgebase.first;
586 if(se->v1->flag + se->v2->flag==1) {
587 if(dir=='h') if(se->v1->vec.y==se->v2->vec.y) {
588 se->v1->flag= se->v2->flag= 1;
591 if(dir=='v') if(se->v1->vec.x==se->v2->vec.x) {
592 se->v1->flag= se->v2->flag= 1;
601 /* test if screen vertices should be scaled */
602 static void screen_test_scale(bScreen *sc, int winsizex, int winsizey)
607 float facx, facy, tempf, min[2], max[2];
610 min[0]= min[1]= 10000.0f;
611 max[0]= max[1]= 0.0f;
613 for(sv= sc->vertbase.first; sv; sv= sv->next) {
614 min[0]= MIN2(min[0], sv->vec.x);
615 min[1]= MIN2(min[1], sv->vec.y);
616 max[0]= MAX2(max[0], sv->vec.x);
617 max[1]= MAX2(max[1], sv->vec.y);
620 /* always make 0.0 left under */
621 for(sv= sc->vertbase.first; sv; sv= sv->next) {
626 sizex= max[0]-min[0];
627 sizey= max[1]-min[1];
629 if(sizex!= winsizex || sizey!= winsizey) {
635 /* make sure it fits! */
636 for(sv= sc->vertbase.first; sv; sv= sv->next) {
637 tempf= ((float)sv->vec.x)*facx;
638 sv->vec.x= (short)(tempf+0.5);
639 sv->vec.x+= AREAGRID-1;
640 sv->vec.x-= (sv->vec.x % AREAGRID);
642 CLAMP(sv->vec.x, 0, winsizex);
644 tempf= ((float)sv->vec.y )*facy;
645 sv->vec.y= (short)(tempf+0.5);
646 sv->vec.y+= AREAGRID-1;
647 sv->vec.y-= (sv->vec.y % AREAGRID);
649 CLAMP(sv->vec.y, 0, winsizey);
653 /* test for collapsed areas. This could happen in some blender version... */
654 /* ton: removed option now, it needs Context... */
656 /* make each window at least HEADERY high */
657 for(sa= sc->areabase.first; sa; sa= sa->next) {
658 int headery= HEADERY+1;
660 if(sa->v1->vec.y+headery > sa->v2->vec.y) {
662 ScrEdge *se= screen_findedge(sc, sa->v4, sa->v1);
663 if(se && sa->v1!=sa->v2 ) {
666 select_connected_scredge(sc, se);
668 /* all selected vertices get the right offset */
669 yval= sa->v2->vec.y-headery;
670 sv= sc->vertbase.first;
672 /* if is a collapsed area */
673 if(sv!=sa->v2 && sv!=sa->v3) {
674 if(sv->flag) sv->vec.y= yval;
684 /* *********************** DRAWING **************************************** */
687 #define SCR_BACK 0.55
690 /* draw vertical shape visualising future joining (left as well
691 * right direction of future joining) */
692 static void draw_horizontal_join_shape(ScrArea *sa, char dir)
697 float width = sa->v3->vec.x - sa->v1->vec.x;
698 float height = sa->v3->vec.y - sa->v1->vec.y;
709 points[0].x = sa->v1->vec.x;
710 points[0].y = sa->v1->vec.y + height/2;
712 points[1].x = sa->v1->vec.x;
713 points[1].y = sa->v1->vec.y;
715 points[2].x = sa->v4->vec.x - w;
716 points[2].y = sa->v4->vec.y;
718 points[3].x = sa->v4->vec.x - w;
719 points[3].y = sa->v4->vec.y + height/2 - 2*h;
721 points[4].x = sa->v4->vec.x - 2*w;
722 points[4].y = sa->v4->vec.y + height/2;
724 points[5].x = sa->v4->vec.x - w;
725 points[5].y = sa->v4->vec.y + height/2 + 2*h;
727 points[6].x = sa->v3->vec.x - w;
728 points[6].y = sa->v3->vec.y;
730 points[7].x = sa->v2->vec.x;
731 points[7].y = sa->v2->vec.y;
733 points[8].x = sa->v4->vec.x;
734 points[8].y = sa->v4->vec.y + height/2 - h;
736 points[9].x = sa->v4->vec.x;
737 points[9].y = sa->v4->vec.y + height/2 + h;
740 /* when direction is left, then we flip direction of arrow */
741 float cx = sa->v1->vec.x + width;
744 points[i].x = -points[i].x;
745 points[i].x += sa->v1->vec.x;
751 glVertex2f(points[i].x, points[i].y);
755 glVertex2f(points[i].x, points[i].y);
756 glVertex2f(points[0].x, points[0].y);
759 glRectf(points[2].x, points[2].y, points[8].x, points[8].y);
760 glRectf(points[6].x, points[6].y, points[9].x, points[9].y);
763 /* draw vertical shape visualising future joining (up/down direction) */
764 static void draw_vertical_join_shape(ScrArea *sa, char dir)
769 float width = sa->v3->vec.x - sa->v1->vec.x;
770 float height = sa->v3->vec.y - sa->v1->vec.y;
781 points[0].x = sa->v1->vec.x + width/2;
782 points[0].y = sa->v3->vec.y;
784 points[1].x = sa->v2->vec.x;
785 points[1].y = sa->v2->vec.y;
787 points[2].x = sa->v1->vec.x;
788 points[2].y = sa->v1->vec.y + h;
790 points[3].x = sa->v1->vec.x + width/2 - 2*w;
791 points[3].y = sa->v1->vec.y + h;
793 points[4].x = sa->v1->vec.x + width/2;
794 points[4].y = sa->v1->vec.y + 2*h;
796 points[5].x = sa->v1->vec.x + width/2 + 2*w;
797 points[5].y = sa->v1->vec.y + h;
799 points[6].x = sa->v4->vec.x;
800 points[6].y = sa->v4->vec.y + h;
802 points[7].x = sa->v3->vec.x;
803 points[7].y = sa->v3->vec.y;
805 points[8].x = sa->v1->vec.x + width/2 - w;
806 points[8].y = sa->v1->vec.y;
808 points[9].x = sa->v1->vec.x + width/2 + w;
809 points[9].y = sa->v1->vec.y;
812 /* when direction is up, then we flip direction of arrow */
813 float cy = sa->v1->vec.y + height;
816 points[i].y = -points[i].y;
817 points[i].y += sa->v1->vec.y;
823 glVertex2f(points[i].x, points[i].y);
827 glVertex2f(points[i].x, points[i].y);
828 glVertex2f(points[0].x, points[0].y);
831 glRectf(points[2].x, points[2].y, points[8].x, points[8].y);
832 glRectf(points[6].x, points[6].y, points[9].x, points[9].y);
835 /* draw join shape due to direction of joining */
836 static void draw_join_shape(ScrArea *sa, char dir)
838 if(dir=='u' || dir=='d')
839 draw_vertical_join_shape(sa, dir);
841 draw_horizontal_join_shape(sa, dir);
844 /* draw screen area darker with arrow (visualisation of future joining) */
845 static void scrarea_draw_shape_dark(ScrArea *sa, char dir)
847 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
849 glColor4ub(0, 0, 0, 50);
850 draw_join_shape(sa, dir);
854 /* draw screen area ligher with arrow shape ("eraser" of previous dark shape) */
855 static void scrarea_draw_shape_light(ScrArea *sa, char dir)
857 glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA);
859 /* value 181 was hardly computed: 181~105 */
860 glColor4ub(255, 255, 255, 50);
861 /* draw_join_shape(sa, dir); */
862 glRecti(sa->v1->vec.x, sa->v1->vec.y, sa->v3->vec.x, sa->v3->vec.y);
866 /** screen edges drawing **/
867 static void drawscredge_area(ScrArea *sa)
869 short x1= sa->v1->vec.x;
870 short y1= sa->v1->vec.y;
871 short x2= sa->v3->vec.x;
872 short y2= sa->v3->vec.y;
876 /* right border area */
877 sdrawline(x2, y1, x2, y2);
879 /* left border area */
880 if(x1>0) { /* otherwise it draws the emboss of window over */
881 sdrawline(x1, y1, x1, y2);
884 /* top border area */
885 sdrawline(x1, y2, x2, y2);
887 /* bottom border area */
888 sdrawline(x1, y1, x2, y1);
892 /* ****************** EXPORTED API TO OTHER MODULES *************************** */
894 bScreen *ED_screen_duplicate(wmWindow *win, bScreen *sc)
898 if(sc->full != SCREENNORMAL) return NULL; /* XXX handle this case! */
900 /* make new empty screen: */
901 newsc= screen_add(win, sc->scene, sc->id.name+2);
903 screen_copy(newsc, sc);
910 /* screen sets cursor based on swinid */
911 static void region_cursor_set(wmWindow *win, int swinid)
913 ScrArea *sa= win->screen->areabase.first;
915 for(;sa; sa= sa->next) {
916 ARegion *ar= sa->regionbase.first;
917 for(;ar; ar= ar->next) {
918 if(ar->swinid == swinid) {
919 if(ar->type && ar->type->cursor)
920 ar->type->cursor(win, sa, ar);
922 WM_cursor_set(win, CURSOR_STD);
929 void ED_screen_do_listen(wmWindow *win, wmNotifier *note)
933 switch(note->category) {
935 win->screen->do_draw= 1;
938 if(note->action==NA_EDITED)
939 win->screen->do_draw= win->screen->do_refresh= 1;
941 if(note->data==ND_MODE)
942 region_cursor_set(win, note->swinid);
947 /* only for edge lines between areas, and the blended join arrows */
948 void ED_screen_draw(wmWindow *win)
956 wmSubWindowSet(win, win->screen->mainwin);
958 for(sa= win->screen->areabase.first; sa; sa= sa->next) {
959 if (sa->flag & AREA_FLAG_DRAWJOINFROM) sa1 = sa;
960 if (sa->flag & AREA_FLAG_DRAWJOINTO) sa2 = sa;
961 drawscredge_area(sa);
964 /* blended join arrow */
966 dir = area_getorientation(win->screen, sa1, sa2);
987 scrarea_draw_shape_dark(sa2, dir);
988 scrarea_draw_shape_light(sa1, dira);
991 if(G.f & G_DEBUG) printf("draw screen\n");
992 win->screen->do_draw= 0;
995 /* make this screen usable */
996 /* for file read and first use, for scaling window, area moves */
997 void ED_screen_refresh(wmWindowManager *wm, wmWindow *win)
1000 rcti winrct= {0, win->sizex-1, 0, win->sizey-1};
1002 screen_test_scale(win->screen, win->sizex, win->sizey);
1004 if(win->screen->mainwin==0)
1005 win->screen->mainwin= wm_subwindow_open(win, &winrct);
1007 wm_subwindow_position(win, win->screen->mainwin, &winrct);
1009 for(sa= win->screen->areabase.first; sa; sa= sa->next) {
1010 /* set spacetype and region callbacks, calls init() */
1011 /* sets subwindows for regions, adds handlers */
1012 ED_area_initialize(wm, win, sa);
1015 /* wake up animtimer */
1016 if(win->screen->animtimer)
1017 WM_event_window_timer_sleep(win, win->screen->animtimer, 0);
1019 if(G.f & G_DEBUG) printf("set screen\n");
1020 win->screen->do_refresh= 0;
1022 win->screen->context= ed_screen_context;
1025 /* file read, set all screens, ... */
1026 void ED_screens_initialize(wmWindowManager *wm)
1030 for(win= wm->windows.first; win; win= win->next) {
1032 if(win->screen==NULL)
1033 win->screen= G.main->screen.first;
1035 ED_screen_refresh(wm, win);
1040 /* *********** exit calls are for closing running stuff ******** */
1042 void ED_region_exit(bContext *C, ARegion *ar)
1044 ARegion *prevar= CTX_wm_region(C);
1046 CTX_wm_region_set(C, ar);
1047 WM_event_remove_handlers(C, &ar->handlers);
1049 wm_subwindow_close(CTX_wm_window(C), ar->swinid);
1053 MEM_freeN(ar->headerstr);
1054 ar->headerstr= NULL;
1056 CTX_wm_region_set(C, prevar);
1059 void ED_area_exit(bContext *C, ScrArea *sa)
1061 ScrArea *prevsa= CTX_wm_area(C);
1064 CTX_wm_area_set(C, sa);
1065 for(ar= sa->regionbase.first; ar; ar= ar->next)
1066 ED_region_exit(C, ar);
1068 WM_event_remove_handlers(C, &sa->handlers);
1069 CTX_wm_area_set(C, prevsa);
1072 void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
1074 wmWindow *prevwin= CTX_wm_window(C);
1078 CTX_wm_window_set(C, window);
1080 if(screen->animtimer)
1081 WM_event_remove_window_timer(window, screen->animtimer);
1082 screen->animtimer= NULL;
1084 for(ar= screen->regionbase.first; ar; ar= ar->next)
1085 ED_region_exit(C, ar);
1087 for(sa= screen->areabase.first; sa; sa= sa->next)
1088 ED_area_exit(C, sa);
1090 CTX_wm_window_set(C, prevwin);
1093 /* *********************************** */
1095 /* case when on area-edge or in azones, or outside window */
1096 static void screen_cursor_set(wmWindow *win, wmEvent *event)
1100 for(sa= win->screen->areabase.first; sa; sa= sa->next)
1101 if(is_in_area_actionzone(sa, event->x, event->y))
1105 WM_cursor_set(win, CURSOR_EDIT);
1108 ScrEdge *actedge= screen_find_active_scredge(win->screen, event->x, event->y);
1111 if(scredge_is_horizontal(actedge))
1112 WM_cursor_set(win, CURSOR_Y_MOVE);
1114 WM_cursor_set(win, CURSOR_X_MOVE);
1117 WM_cursor_set(win, CURSOR_STD);
1122 /* called in wm_event_system.c. sets state vars in screen, cursors */
1123 /* event type is mouse move */
1124 void ED_screen_set_subwinactive(wmWindow *win, wmEvent *event)
1127 bScreen *scr= win->screen;
1130 int oldswin= scr->subwinactive;
1132 for(sa= scr->areabase.first; sa; sa= sa->next) {
1133 if(event->x > sa->totrct.xmin && event->x < sa->totrct.xmax)
1134 if(event->y > sa->totrct.ymin && event->y < sa->totrct.ymax)
1135 if(NULL==is_in_area_actionzone(sa, event->x, event->y))
1139 for(ar= sa->regionbase.first; ar; ar= ar->next) {
1140 if(BLI_in_rcti(&ar->winrct, event->x, event->y))
1141 scr->subwinactive= ar->swinid;
1145 scr->subwinactive= scr->mainwin;
1147 /* check for redraw headers */
1148 if(oldswin!=scr->subwinactive) {
1150 for(sa= scr->areabase.first; sa; sa= sa->next) {
1153 for(ar= sa->regionbase.first; ar; ar= ar->next)
1154 if(ar->swinid==oldswin || ar->swinid==scr->subwinactive)
1158 for(ar= sa->regionbase.first; ar; ar= ar->next)
1159 if(ar->regiontype==RGN_TYPE_HEADER)
1160 ED_region_tag_redraw(ar);
1165 /* cursors, for time being set always on edges, otherwise aregion doesnt switch */
1166 if(scr->subwinactive==scr->mainwin) {
1167 screen_cursor_set(win, event);
1169 else if(oldswin!=scr->subwinactive) {
1170 region_cursor_set(win, scr->subwinactive);
1175 int ED_screen_area_active(const bContext *C)
1177 bScreen *sc= CTX_wm_screen(C);
1178 ScrArea *sa= CTX_wm_area(C);
1182 for(ar= sa->regionbase.first; ar; ar= ar->next)
1183 if(ar->swinid == sc->subwinactive)
1189 /* operator call, WM + Window + screen already existed before */
1190 /* Do NOT call in area/region queues! */
1191 void ed_screen_set(bContext *C, bScreen *sc)
1193 bScreen *oldscreen= CTX_wm_screen(C);
1195 if(sc->full) { /* find associated full */
1197 for(sc1= G.main->screen.first; sc1; sc1= sc1->id.next) {
1198 ScrArea *sa= sc1->areabase.first;
1204 if(sc1==NULL) printf("set screen error\n");
1207 if (oldscreen != sc) {
1208 wmWindow *win= CTX_wm_window(C);
1209 wmTimer *wt= oldscreen->animtimer;
1211 /* we put timer to sleep, so screen_exit has to think there's no timer */
1212 oldscreen->animtimer= NULL;
1214 WM_event_window_timer_sleep(win, wt, 1);
1216 ED_screen_exit(C, win, oldscreen);
1217 oldscreen->animtimer= wt;
1220 CTX_wm_window_set(C, win); // stores C->wm.screen... hrmf
1222 ED_screen_refresh(CTX_wm_manager(C), CTX_wm_window(C));
1223 WM_event_add_notifier(C, NC_WINDOW, NULL);
1227 /* this function toggles: if area is full then the parent will be restored */
1228 void ed_screen_fullarea(bContext *C)
1230 bScreen *sc, *oldscreen;
1231 ScrArea *newa, *old;
1234 if(CTX_wm_area(C)->full) {
1235 sc= CTX_wm_area(C)->full; /* the old screen to restore */
1236 oldscreen= CTX_wm_screen(C); /* the one disappearing */
1238 fulltype = sc->full;
1240 /* refuse to go out of SCREENAUTOPLAY as long as G_FLAGS_AUTOPLAY
1243 if (fulltype != SCREENAUTOPLAY || (G.flags & G_FILE_AUTOPLAY) == 0) {
1247 for(old= sc->areabase.first; old; old= old->next)
1248 if(old->full) break;
1250 printf("something wrong in areafullscreen\n");
1253 // old feature described below (ton)
1254 // in autoplay screens the headers are disabled by
1255 // default. So use the old headertype instead
1257 area_copy_data(old, CTX_wm_area(C), 1); /* 1 = swap spacelist */
1261 /* animtimer back */
1262 sc->animtimer= oldscreen->animtimer;
1263 oldscreen->animtimer= NULL;
1265 ed_screen_set(C, sc);
1267 free_screen(oldscreen);
1268 free_libblock(&G.main->screen, oldscreen);
1272 oldscreen= CTX_wm_screen(C);
1274 /* is there only 1 area? */
1275 if(oldscreen->areabase.first==CTX_wm_screen(C)->areabase.last) return;
1276 if(CTX_wm_area(C)->spacetype==SPACE_INFO) return;
1278 oldscreen->full = SCREENFULL;
1280 sc= screen_add(CTX_wm_window(C), CTX_data_scene(C), "temp");
1283 sc->animtimer= oldscreen->animtimer;
1284 oldscreen->animtimer= NULL;
1286 /* returns the top small area */
1287 newa= area_split(CTX_wm_window(C), sc, (ScrArea *)sc->areabase.first, 'h', 0.99f);
1288 ED_area_newspace(C, newa, SPACE_INFO);
1292 area_copy_data(newa, CTX_wm_area(C), 1); /* 1 = swap spacelist */
1294 CTX_wm_area(C)->full= oldscreen;
1295 newa->full= oldscreen;
1296 newa->next->full= oldscreen;
1298 ed_screen_set(C, sc);
1301 /* XXX bad code: setscreen() ends with first area active. fullscreen render assumes this too */
1302 CTX_wm_area_set(C, sc->areabase.first);
1304 /* XXX retopo_force_update(); */
1308 void ED_screen_full_newspace(bContext *C, ScrArea *sa, int type)
1311 ed_screen_fullarea(C);
1313 ED_area_newspace(C, CTX_wm_area(C), type);
1316 void ED_screen_full_prevspace(bContext *C)
1318 ScrArea *sa= CTX_wm_area(C);
1320 ED_area_prevspace(C);
1323 ed_screen_fullarea(C);
1326 void ED_screen_animation_timer(bContext *C, int enable)
1328 bScreen *screen= CTX_wm_screen(C);
1329 wmWindow *win= CTX_wm_window(C);
1330 Scene *scene= CTX_data_scene(C);
1332 if(screen->animtimer)
1333 WM_event_remove_window_timer(win, screen->animtimer);
1334 screen->animtimer= NULL;
1337 screen->animtimer= WM_event_add_window_timer(win, TIMER0, (1.0/FPS));