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"
34 #include "DNA_texture_types.h"
35 #include "DNA_userdef_types.h"
37 #include "BLI_blenlib.h"
39 #include "BKE_context.h"
40 #include "BKE_global.h"
41 #include "BKE_library.h"
44 #include "BKE_screen.h"
45 #include "BKE_scene.h"
46 #include "BKE_utildefines.h"
49 #include "BIF_glutil.h"
54 #include "ED_screen.h"
55 #include "ED_screen_types.h"
57 /* XXX actually should be not here... solve later */
58 #include "wm_subwindow.h"
60 #include "screen_intern.h" /* own module include */
63 /* ******************* screen vert, edge, area managing *********************** */
65 static ScrVert *screen_addvert(bScreen *sc, short x, short y)
67 ScrVert *sv= MEM_callocN(sizeof(ScrVert), "addscrvert");
71 BLI_addtail(&sc->vertbase, sv);
75 static void sortscrvert(ScrVert **v1, ScrVert **v2)
86 static ScrEdge *screen_addedge(bScreen *sc, ScrVert *v1, ScrVert *v2)
88 ScrEdge *se= MEM_callocN(sizeof(ScrEdge), "addscredge");
90 sortscrvert(&v1, &v2);
94 BLI_addtail(&sc->edgebase, se);
99 ScrEdge *screen_findedge(bScreen *sc, ScrVert *v1, ScrVert *v2)
103 sortscrvert(&v1, &v2);
104 for (se= sc->edgebase.first; se; se= se->next)
105 if(se->v1==v1 && se->v2==v2)
111 void removedouble_scrverts(bScreen *sc)
117 verg= sc->vertbase.first;
119 if(verg->newv==NULL) { /* !!! */
122 if(v1->newv==NULL) { /* !?! */
123 if(v1->vec.x==verg->vec.x && v1->vec.y==verg->vec.y) {
124 /* printf("doublevert\n"); */
134 /* replace pointers in edges and faces */
135 se= sc->edgebase.first;
137 if(se->v1->newv) se->v1= se->v1->newv;
138 if(se->v2->newv) se->v2= se->v2->newv;
139 /* edges changed: so.... */
140 sortscrvert(&(se->v1), &(se->v2));
143 sa= sc->areabase.first;
145 if(sa->v1->newv) sa->v1= sa->v1->newv;
146 if(sa->v2->newv) sa->v2= sa->v2->newv;
147 if(sa->v3->newv) sa->v3= sa->v3->newv;
148 if(sa->v4->newv) sa->v4= sa->v4->newv;
153 verg= sc->vertbase.first;
157 BLI_remlink(&sc->vertbase, verg);
165 void removenotused_scrverts(bScreen *sc)
170 /* we assume edges are ok */
172 se= sc->edgebase.first;
179 sv= sc->vertbase.first;
183 BLI_remlink(&sc->vertbase, sv);
191 void removedouble_scredges(bScreen *sc)
193 ScrEdge *verg, *se, *sn;
196 verg= sc->edgebase.first;
201 if(verg->v1==se->v1 && verg->v2==se->v2) {
202 BLI_remlink(&sc->edgebase, se);
211 void removenotused_scredges(bScreen *sc)
217 /* sets flags when edge is used in area */
218 sa= sc->areabase.first;
220 se= screen_findedge(sc, sa->v1, sa->v2);
221 if(se==0) printf("error: area %d edge 1 doesn't exist\n", a);
223 se= screen_findedge(sc, sa->v2, sa->v3);
224 if(se==0) printf("error: area %d edge 2 doesn't exist\n", a);
226 se= screen_findedge(sc, sa->v3, sa->v4);
227 if(se==0) printf("error: area %d edge 3 doesn't exist\n", a);
229 se= screen_findedge(sc, sa->v4, sa->v1);
230 if(se==0) printf("error: area %d edge 4 doesn't exist\n", a);
235 se= sc->edgebase.first;
239 BLI_remlink(&sc->edgebase, se);
247 int scredge_is_horizontal(ScrEdge *se)
249 return (se->v1->vec.y == se->v2->vec.y);
252 ScrEdge *screen_find_active_scredge(bScreen *sc, int mx, int my)
256 for (se= sc->edgebase.first; se; se= se->next) {
257 if (scredge_is_horizontal(se)) {
259 min= MIN2(se->v1->vec.x, se->v2->vec.x);
260 max= MAX2(se->v1->vec.x, se->v2->vec.x);
262 if (abs(my-se->v1->vec.y)<=2 && mx>=min && mx<=max)
267 min= MIN2(se->v1->vec.y, se->v2->vec.y);
268 max= MAX2(se->v1->vec.y, se->v2->vec.y);
270 if (abs(mx-se->v1->vec.x)<=2 && my>=min && my<=max)
280 /* adds no space data */
281 static ScrArea *screen_addarea(bScreen *sc, ScrVert *v1, ScrVert *v2, ScrVert *v3, ScrVert *v4, short headertype, short spacetype)
283 ScrArea *sa= MEM_callocN(sizeof(ScrArea), "addscrarea");
288 sa->headertype= headertype;
289 sa->spacetype= sa->butspacetype= spacetype;
291 BLI_addtail(&sc->areabase, sa);
296 static void screen_delarea(bContext *C, bScreen *sc, ScrArea *sa)
301 BKE_screen_area_free(sa);
303 BLI_remlink(&sc->areabase, sa);
307 /* return 0: no split possible */
308 /* else return (integer) screencoordinate split point */
309 static short testsplitpoint(wmWindow *win, ScrArea *sa, char dir, float fac)
314 if(dir=='v' && (sa->v4->vec.x- sa->v1->vec.x <= 2*AREAMINX)) return 0;
315 if(dir=='h' && (sa->v2->vec.y- sa->v1->vec.y <= 2*AREAMINY)) return 0;
318 if(fac<0.0) fac= 0.0;
319 if(fac>1.0) fac= 1.0;
322 y= sa->v1->vec.y+ fac*(sa->v2->vec.y- sa->v1->vec.y);
324 if(y- sa->v1->vec.y < AREAMINY)
325 y= sa->v1->vec.y+ AREAMINY;
326 else if(sa->v2->vec.y- y < AREAMINY)
327 y= sa->v2->vec.y- AREAMINY;
328 else y-= (y % AREAGRID);
333 x= sa->v1->vec.x+ fac*(sa->v4->vec.x- sa->v1->vec.x);
335 if(x- sa->v1->vec.x < AREAMINX)
336 x= sa->v1->vec.x+ AREAMINX;
337 else if(sa->v4->vec.x- x < AREAMINX)
338 x= sa->v4->vec.x- AREAMINX;
339 else x-= (x % AREAGRID);
345 ScrArea *area_split(wmWindow *win, bScreen *sc, ScrArea *sa, char dir, float fac)
351 if(sa==NULL) return NULL;
353 split= testsplitpoint(win, sa, dir, fac);
354 if(split==0) return NULL;
358 sv1= screen_addvert(sc, sa->v1->vec.x, split);
359 sv2= screen_addvert(sc, sa->v4->vec.x, split);
362 screen_addedge(sc, sa->v1, sv1);
363 screen_addedge(sc, sv1, sa->v2);
364 screen_addedge(sc, sa->v3, sv2);
365 screen_addedge(sc, sv2, sa->v4);
366 screen_addedge(sc, sv1, sv2);
369 newa= screen_addarea(sc, sv1, sa->v2, sa->v3, sv2, sa->headertype, sa->spacetype);
370 area_copy_data(newa, sa, 0);
379 sv1= screen_addvert(sc, split, sa->v1->vec.y);
380 sv2= screen_addvert(sc, split, sa->v2->vec.y);
383 screen_addedge(sc, sa->v1, sv1);
384 screen_addedge(sc, sv1, sa->v4);
385 screen_addedge(sc, sa->v2, sv2);
386 screen_addedge(sc, sv2, sa->v3);
387 screen_addedge(sc, sv1, sv2);
389 /* new areas: left */
390 newa= screen_addarea(sc, sa->v1, sa->v2, sv2, sv1, sa->headertype, sa->spacetype);
391 area_copy_data(newa, sa, 0);
398 /* remove double vertices en edges */
399 removedouble_scrverts(sc);
400 removedouble_scredges(sc);
401 removenotused_scredges(sc);
406 /* empty screen, with 1 dummy area without spacedata */
407 /* uses window size */
408 bScreen *ED_screen_add(wmWindow *win, Scene *scene, char *name)
411 ScrVert *sv1, *sv2, *sv3, *sv4;
413 sc= alloc_libblock(&G.main->screen, ID_SCR, name);
416 sc->winid= win->winid;
418 sv1= screen_addvert(sc, 0, 0);
419 sv2= screen_addvert(sc, 0, win->sizey-1);
420 sv3= screen_addvert(sc, win->sizex-1, win->sizey-1);
421 sv4= screen_addvert(sc, win->sizex-1, 0);
423 screen_addedge(sc, sv1, sv2);
424 screen_addedge(sc, sv2, sv3);
425 screen_addedge(sc, sv3, sv4);
426 screen_addedge(sc, sv4, sv1);
428 /* dummy type, no spacedata */
429 screen_addarea(sc, sv1, sv2, sv3, sv4, HEADERDOWN, SPACE_EMPTY);
434 static void screen_copy(bScreen *to, bScreen *from)
440 /* free contents of 'to', is from blenkernel screen.c */
443 BLI_duplicatelist(&to->vertbase, &from->vertbase);
444 BLI_duplicatelist(&to->edgebase, &from->edgebase);
445 BLI_duplicatelist(&to->areabase, &from->areabase);
446 to->regionbase.first= to->regionbase.last= NULL;
448 s2= to->vertbase.first;
449 for(s1= from->vertbase.first; s1; s1= s1->next, s2= s2->next) {
453 for(se= to->edgebase.first; se; se= se->next) {
454 se->v1= se->v1->newv;
455 se->v2= se->v2->newv;
456 sortscrvert(&(se->v1), &(se->v2));
459 saf= from->areabase.first;
460 for(sa= to->areabase.first; sa; sa= sa->next, saf= saf->next) {
461 sa->v1= sa->v1->newv;
462 sa->v2= sa->v2->newv;
463 sa->v3= sa->v3->newv;
464 sa->v4= sa->v4->newv;
466 sa->spacedata.first= sa->spacedata.last= NULL;
467 sa->regionbase.first= sa->regionbase.last= NULL;
468 sa->actionzones.first= sa->actionzones.last= NULL;
470 area_copy_data(sa, saf, 0);
473 /* put at zero (needed?) */
474 for(s1= from->vertbase.first; s1; s1= s1->next)
480 /* with sa as center, sb is located at: 0=W, 1=N, 2=E, 3=S */
481 /* -1 = not valid check */
482 /* used with join operator */
483 int area_getorientation(bScreen *screen, ScrArea *sa, ScrArea *sb)
485 ScrVert *sav1, *sav2, *sav3, *sav4;
486 ScrVert *sbv1, *sbv2, *sbv3, *sbv4;
488 if(sa==NULL || sb==NULL) return -1;
499 if(sav1==sbv4 && sav2==sbv3) { /* sa to right of sb = W */
502 else if(sav2==sbv1 && sav3==sbv4) { /* sa to bottom of sb = N */
505 else if(sav3==sbv2 && sav4==sbv1) { /* sa to left of sb = E */
508 else if(sav1==sbv2 && sav4==sbv3) { /* sa on top of sb = S*/
515 /* Helper function to join 2 areas, it has a return value, 0=failed 1=success
516 * used by the split, join operators
518 int screen_area_join(bContext *C, bScreen* scr, ScrArea *sa1, ScrArea *sa2)
522 dir = area_getorientation(scr, sa1, sa2);
523 /*printf("dir is : %i \n", dir);*/
527 if (sa1 ) sa1->flag &= ~AREA_FLAG_DRAWJOINFROM;
528 if (sa2 ) sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
535 screen_addedge(scr, sa1->v2, sa1->v3);
536 screen_addedge(scr, sa1->v1, sa1->v4);
541 screen_addedge(scr, sa1->v1, sa1->v2);
542 screen_addedge(scr, sa1->v3, sa1->v4);
547 screen_addedge(scr, sa1->v2, sa1->v3);
548 screen_addedge(scr, sa1->v1, sa1->v4);
553 screen_addedge(scr, sa1->v1, sa1->v2);
554 screen_addedge(scr, sa1->v3, sa1->v4);
557 screen_delarea(C, scr, sa2);
558 removedouble_scrverts(scr);
559 sa1->flag &= ~AREA_FLAG_DRAWJOINFROM;
564 void select_connected_scredge(bScreen *sc, ScrEdge *edge)
571 /* select connected, only in the right direction */
572 /* 'dir' is the direction of EDGE */
574 if(edge->v1->vec.x==edge->v2->vec.x) dir= 'v';
577 sv= sc->vertbase.first;
588 se= sc->edgebase.first;
591 if(se->v1->flag + se->v2->flag==1) {
592 if(dir=='h') if(se->v1->vec.y==se->v2->vec.y) {
593 se->v1->flag= se->v2->flag= 1;
596 if(dir=='v') if(se->v1->vec.x==se->v2->vec.x) {
597 se->v1->flag= se->v2->flag= 1;
606 /* test if screen vertices should be scaled */
607 static void screen_test_scale(bScreen *sc, int winsizex, int winsizey)
612 float facx, facy, tempf, min[2], max[2];
615 min[0]= min[1]= 10000.0f;
616 max[0]= max[1]= 0.0f;
618 for(sv= sc->vertbase.first; sv; sv= sv->next) {
619 min[0]= MIN2(min[0], sv->vec.x);
620 min[1]= MIN2(min[1], sv->vec.y);
621 max[0]= MAX2(max[0], sv->vec.x);
622 max[1]= MAX2(max[1], sv->vec.y);
625 /* always make 0.0 left under */
626 for(sv= sc->vertbase.first; sv; sv= sv->next) {
631 sizex= max[0]-min[0];
632 sizey= max[1]-min[1];
634 if(sizex!= winsizex || sizey!= winsizey) {
640 /* make sure it fits! */
641 for(sv= sc->vertbase.first; sv; sv= sv->next) {
642 tempf= ((float)sv->vec.x)*facx;
643 sv->vec.x= (short)(tempf+0.5);
644 sv->vec.x+= AREAGRID-1;
645 sv->vec.x-= (sv->vec.x % AREAGRID);
647 CLAMP(sv->vec.x, 0, winsizex);
649 tempf= ((float)sv->vec.y )*facy;
650 sv->vec.y= (short)(tempf+0.5);
651 sv->vec.y+= AREAGRID-1;
652 sv->vec.y-= (sv->vec.y % AREAGRID);
654 CLAMP(sv->vec.y, 0, winsizey);
658 /* test for collapsed areas. This could happen in some blender version... */
659 /* ton: removed option now, it needs Context... */
661 /* make each window at least HEADERY high */
662 for(sa= sc->areabase.first; sa; sa= sa->next) {
663 int headery= HEADERY+1;
665 if(sa->v1->vec.y+headery > sa->v2->vec.y) {
667 ScrEdge *se= screen_findedge(sc, sa->v4, sa->v1);
668 if(se && sa->v1!=sa->v2 ) {
671 select_connected_scredge(sc, se);
673 /* all selected vertices get the right offset */
674 yval= sa->v2->vec.y-headery;
675 sv= sc->vertbase.first;
677 /* if is a collapsed area */
678 if(sv!=sa->v2 && sv!=sa->v3) {
679 if(sv->flag) sv->vec.y= yval;
689 /* *********************** DRAWING **************************************** */
692 #define SCR_BACK 0.55
695 /* draw vertical shape visualising future joining (left as well
696 * right direction of future joining) */
697 static void draw_horizontal_join_shape(ScrArea *sa, char dir)
702 float width = sa->v3->vec.x - sa->v1->vec.x;
703 float height = sa->v3->vec.y - sa->v1->vec.y;
714 points[0].x = sa->v1->vec.x;
715 points[0].y = sa->v1->vec.y + height/2;
717 points[1].x = sa->v1->vec.x;
718 points[1].y = sa->v1->vec.y;
720 points[2].x = sa->v4->vec.x - w;
721 points[2].y = sa->v4->vec.y;
723 points[3].x = sa->v4->vec.x - w;
724 points[3].y = sa->v4->vec.y + height/2 - 2*h;
726 points[4].x = sa->v4->vec.x - 2*w;
727 points[4].y = sa->v4->vec.y + height/2;
729 points[5].x = sa->v4->vec.x - w;
730 points[5].y = sa->v4->vec.y + height/2 + 2*h;
732 points[6].x = sa->v3->vec.x - w;
733 points[6].y = sa->v3->vec.y;
735 points[7].x = sa->v2->vec.x;
736 points[7].y = sa->v2->vec.y;
738 points[8].x = sa->v4->vec.x;
739 points[8].y = sa->v4->vec.y + height/2 - h;
741 points[9].x = sa->v4->vec.x;
742 points[9].y = sa->v4->vec.y + height/2 + h;
745 /* when direction is left, then we flip direction of arrow */
746 float cx = sa->v1->vec.x + width;
749 points[i].x = -points[i].x;
750 points[i].x += sa->v1->vec.x;
756 glVertex2f(points[i].x, points[i].y);
760 glVertex2f(points[i].x, points[i].y);
761 glVertex2f(points[0].x, points[0].y);
764 glRectf(points[2].x, points[2].y, points[8].x, points[8].y);
765 glRectf(points[6].x, points[6].y, points[9].x, points[9].y);
768 /* draw vertical shape visualising future joining (up/down direction) */
769 static void draw_vertical_join_shape(ScrArea *sa, char dir)
774 float width = sa->v3->vec.x - sa->v1->vec.x;
775 float height = sa->v3->vec.y - sa->v1->vec.y;
786 points[0].x = sa->v1->vec.x + width/2;
787 points[0].y = sa->v3->vec.y;
789 points[1].x = sa->v2->vec.x;
790 points[1].y = sa->v2->vec.y;
792 points[2].x = sa->v1->vec.x;
793 points[2].y = sa->v1->vec.y + h;
795 points[3].x = sa->v1->vec.x + width/2 - 2*w;
796 points[3].y = sa->v1->vec.y + h;
798 points[4].x = sa->v1->vec.x + width/2;
799 points[4].y = sa->v1->vec.y + 2*h;
801 points[5].x = sa->v1->vec.x + width/2 + 2*w;
802 points[5].y = sa->v1->vec.y + h;
804 points[6].x = sa->v4->vec.x;
805 points[6].y = sa->v4->vec.y + h;
807 points[7].x = sa->v3->vec.x;
808 points[7].y = sa->v3->vec.y;
810 points[8].x = sa->v1->vec.x + width/2 - w;
811 points[8].y = sa->v1->vec.y;
813 points[9].x = sa->v1->vec.x + width/2 + w;
814 points[9].y = sa->v1->vec.y;
817 /* when direction is up, then we flip direction of arrow */
818 float cy = sa->v1->vec.y + height;
821 points[i].y = -points[i].y;
822 points[i].y += sa->v1->vec.y;
828 glVertex2f(points[i].x, points[i].y);
832 glVertex2f(points[i].x, points[i].y);
833 glVertex2f(points[0].x, points[0].y);
836 glRectf(points[2].x, points[2].y, points[8].x, points[8].y);
837 glRectf(points[6].x, points[6].y, points[9].x, points[9].y);
840 /* draw join shape due to direction of joining */
841 static void draw_join_shape(ScrArea *sa, char dir)
843 if(dir=='u' || dir=='d')
844 draw_vertical_join_shape(sa, dir);
846 draw_horizontal_join_shape(sa, dir);
849 /* draw screen area darker with arrow (visualisation of future joining) */
850 static void scrarea_draw_shape_dark(ScrArea *sa, char dir)
852 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
854 glColor4ub(0, 0, 0, 50);
855 draw_join_shape(sa, dir);
859 /* draw screen area ligher with arrow shape ("eraser" of previous dark shape) */
860 static void scrarea_draw_shape_light(ScrArea *sa, char dir)
862 glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA);
864 /* value 181 was hardly computed: 181~105 */
865 glColor4ub(255, 255, 255, 50);
866 /* draw_join_shape(sa, dir); */
867 glRecti(sa->v1->vec.x, sa->v1->vec.y, sa->v3->vec.x, sa->v3->vec.y);
871 static void drawscredge_area_draw(int sizex, int sizey, short x1, short y1, short x2, short y2, short a)
873 /* right border area */
875 sdrawline(x2+a, y1, x2+a, y2);
877 /* left border area */
878 if(x1>0) /* otherwise it draws the emboss of window over */
879 sdrawline(x1+a, y1, x1+a, y2);
881 /* top border area */
883 sdrawline(x1, y2+a, x2, y2+a);
885 /* bottom border area */
887 sdrawline(x1, y1+a, x2, y1+a);
891 /** screen edges drawing **/
892 static void drawscredge_area(ScrArea *sa, int sizex, int sizey, int center)
894 short x1= sa->v1->vec.x;
895 short y1= sa->v1->vec.y;
896 short x2= sa->v3->vec.x;
897 short y2= sa->v3->vec.y;
900 rt= CLAMPIS(G.rt, 0, 16);
904 for(a=-rt; a<=rt; a++)
906 drawscredge_area_draw(sizex, sizey, x1, y1, x2, y2, a);
910 drawscredge_area_draw(sizex, sizey, x1, y1, x2, y2, 0);
914 /* ****************** EXPORTED API TO OTHER MODULES *************************** */
916 bScreen *ED_screen_duplicate(wmWindow *win, bScreen *sc)
920 if(sc->full != SCREENNORMAL) return NULL; /* XXX handle this case! */
922 /* make new empty screen: */
923 newsc= ED_screen_add(win, sc->scene, sc->id.name+2);
925 screen_copy(newsc, sc);
929 /* store identifier */
930 win->screen->winid= win->winid;
931 BLI_strncpy(win->screenname, win->screen->id.name+2, 21);
936 /* screen sets cursor based on swinid */
937 static void region_cursor_set(wmWindow *win, int swinid)
939 ScrArea *sa= win->screen->areabase.first;
941 for(;sa; sa= sa->next) {
942 ARegion *ar= sa->regionbase.first;
943 for(;ar; ar= ar->next) {
944 if(ar->swinid == swinid) {
945 if(ar->type && ar->type->cursor)
946 ar->type->cursor(win, sa, ar);
948 WM_cursor_set(win, CURSOR_STD);
955 void ED_screen_do_listen(wmWindow *win, wmNotifier *note)
959 switch(note->category) {
961 if(note->data==ND_FILEREAD)
962 win->screen->do_draw= 1;
965 win->screen->do_draw= 1;
968 if(note->action==NA_EDITED)
969 win->screen->do_draw= win->screen->do_refresh= 1;
971 if(note->data==ND_MODE)
972 region_cursor_set(win, note->swinid);
977 /* only for edge lines between areas, and the blended join arrows */
978 void ED_screen_draw(wmWindow *win)
986 wmSubWindowSet(win, win->screen->mainwin);
988 for(sa= win->screen->areabase.first; sa; sa= sa->next) {
989 if (sa->flag & AREA_FLAG_DRAWJOINFROM) sa1 = sa;
990 if (sa->flag & AREA_FLAG_DRAWJOINTO) sa2 = sa;
991 drawscredge_area(sa, win->sizex, win->sizey, 0);
993 for(sa= win->screen->areabase.first; sa; sa= sa->next)
994 drawscredge_area(sa, win->sizex, win->sizey, 1);
996 /* blended join arrow */
998 dir = area_getorientation(win->screen, sa1, sa2);
1019 scrarea_draw_shape_dark(sa2, dir);
1020 scrarea_draw_shape_light(sa1, dira);
1023 // if(G.f & G_DEBUG) printf("draw screen\n");
1024 win->screen->do_draw= 0;
1027 /* make this screen usable */
1028 /* for file read and first use, for scaling window, area moves */
1029 void ED_screen_refresh(wmWindowManager *wm, wmWindow *win)
1032 rcti winrct= {0, win->sizex-1, 0, win->sizey-1};
1034 screen_test_scale(win->screen, win->sizex, win->sizey);
1036 if(win->screen->mainwin==0)
1037 win->screen->mainwin= wm_subwindow_open(win, &winrct);
1039 wm_subwindow_position(win, win->screen->mainwin, &winrct);
1041 for(sa= win->screen->areabase.first; sa; sa= sa->next) {
1042 /* set spacetype and region callbacks, calls init() */
1043 /* sets subwindows for regions, adds handlers */
1044 ED_area_initialize(wm, win, sa);
1047 /* wake up animtimer */
1048 if(win->screen->animtimer)
1049 WM_event_window_timer_sleep(win, win->screen->animtimer, 0);
1051 if(G.f & G_DEBUG) printf("set screen\n");
1052 win->screen->do_refresh= 0;
1054 win->screen->context= ed_screen_context;
1057 /* file read, set all screens, ... */
1058 void ED_screens_initialize(wmWindowManager *wm)
1062 for(win= wm->windows.first; win; win= win->next) {
1064 if(win->screen==NULL)
1065 win->screen= G.main->screen.first;
1067 ED_screen_refresh(wm, win);
1072 /* *********** exit calls are for closing running stuff ******** */
1074 void ED_region_exit(bContext *C, ARegion *ar)
1076 ARegion *prevar= CTX_wm_region(C);
1078 CTX_wm_region_set(C, ar);
1079 WM_event_remove_handlers(C, &ar->handlers);
1081 wm_subwindow_close(CTX_wm_window(C), ar->swinid);
1085 MEM_freeN(ar->headerstr);
1086 ar->headerstr= NULL;
1088 CTX_wm_region_set(C, prevar);
1091 void ED_area_exit(bContext *C, ScrArea *sa)
1093 ScrArea *prevsa= CTX_wm_area(C);
1096 CTX_wm_area_set(C, sa);
1097 for(ar= sa->regionbase.first; ar; ar= ar->next)
1098 ED_region_exit(C, ar);
1100 WM_event_remove_handlers(C, &sa->handlers);
1101 CTX_wm_area_set(C, prevsa);
1104 void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
1106 wmWindow *prevwin= CTX_wm_window(C);
1110 CTX_wm_window_set(C, window);
1112 if(screen->animtimer)
1113 WM_event_remove_window_timer(window, screen->animtimer);
1114 screen->animtimer= NULL;
1117 wm_subwindow_close(window, screen->mainwin);
1119 screen->subwinactive= 0;
1121 for(ar= screen->regionbase.first; ar; ar= ar->next)
1122 ED_region_exit(C, ar);
1124 for(sa= screen->areabase.first; sa; sa= sa->next)
1125 ED_area_exit(C, sa);
1127 /* mark it available for use for other windows */
1130 CTX_wm_window_set(C, prevwin);
1133 /* *********************************** */
1135 /* case when on area-edge or in azones, or outside window */
1136 static void screen_cursor_set(wmWindow *win, wmEvent *event)
1141 for(sa= win->screen->areabase.first; sa; sa= sa->next)
1142 if((az=is_in_area_actionzone(sa, event->x, event->y)))
1146 if(az->type==AZONE_AREA)
1147 WM_cursor_set(win, CURSOR_EDIT);
1148 else if(az->type==AZONE_REGION) {
1150 WM_cursor_set(win, CURSOR_X_MOVE);
1152 WM_cursor_set(win, CURSOR_Y_MOVE);
1156 ScrEdge *actedge= screen_find_active_scredge(win->screen, event->x, event->y);
1159 if(scredge_is_horizontal(actedge))
1160 WM_cursor_set(win, CURSOR_Y_MOVE);
1162 WM_cursor_set(win, CURSOR_X_MOVE);
1165 WM_cursor_set(win, CURSOR_STD);
1170 /* called in wm_event_system.c. sets state vars in screen, cursors */
1171 /* event type is mouse move */
1172 void ED_screen_set_subwinactive(wmWindow *win, wmEvent *event)
1175 bScreen *scr= win->screen;
1178 int oldswin= scr->subwinactive;
1180 for(sa= scr->areabase.first; sa; sa= sa->next) {
1181 if(event->x > sa->totrct.xmin && event->x < sa->totrct.xmax)
1182 if(event->y > sa->totrct.ymin && event->y < sa->totrct.ymax)
1183 if(NULL==is_in_area_actionzone(sa, event->x, event->y))
1187 for(ar= sa->regionbase.first; ar; ar= ar->next) {
1188 if(BLI_in_rcti(&ar->winrct, event->x, event->y))
1189 scr->subwinactive= ar->swinid;
1193 scr->subwinactive= scr->mainwin;
1195 /* check for redraw headers */
1196 if(oldswin!=scr->subwinactive) {
1198 for(sa= scr->areabase.first; sa; sa= sa->next) {
1201 for(ar= sa->regionbase.first; ar; ar= ar->next)
1202 if(ar->swinid==oldswin || ar->swinid==scr->subwinactive)
1206 for(ar= sa->regionbase.first; ar; ar= ar->next)
1207 if(ar->regiontype==RGN_TYPE_HEADER)
1208 ED_region_tag_redraw(ar);
1213 /* cursors, for time being set always on edges, otherwise aregion doesnt switch */
1214 if(scr->subwinactive==scr->mainwin) {
1215 screen_cursor_set(win, event);
1217 else if(oldswin!=scr->subwinactive) {
1218 region_cursor_set(win, scr->subwinactive);
1223 int ED_screen_area_active(const bContext *C)
1225 bScreen *sc= CTX_wm_screen(C);
1226 ScrArea *sa= CTX_wm_area(C);
1230 for(ar= sa->regionbase.first; ar; ar= ar->next)
1231 if(ar->swinid == sc->subwinactive)
1237 /* operator call, WM + Window + screen already existed before */
1238 /* Do NOT call in area/region queues! */
1239 void ED_screen_set(bContext *C, bScreen *sc)
1241 wmWindow *win= CTX_wm_window(C);
1242 bScreen *oldscreen= CTX_wm_screen(C);
1245 /* validate screen, it's called with notifier reference */
1246 for(id= CTX_data_main(C)->screen.first; id; id= id->next)
1247 if(sc == (bScreen *)id)
1252 /* check for valid winid */
1253 if(sc->winid!=0 && sc->winid!=win->winid)
1256 if(sc->full) { /* find associated full */
1258 for(sc1= CTX_data_main(C)->screen.first; sc1; sc1= sc1->id.next) {
1259 ScrArea *sa= sc1->areabase.first;
1267 if (oldscreen != sc) {
1268 wmTimer *wt= oldscreen->animtimer;
1270 /* we put timer to sleep, so screen_exit has to think there's no timer */
1271 oldscreen->animtimer= NULL;
1273 WM_event_window_timer_sleep(win, wt, 1);
1275 ED_screen_exit(C, win, oldscreen);
1276 oldscreen->animtimer= wt;
1279 CTX_wm_window_set(C, win); // stores C->wm.screen... hrmf
1281 /* prevent multiwin errors */
1282 sc->winid= win->winid;
1284 ED_screen_refresh(CTX_wm_manager(C), CTX_wm_window(C));
1285 WM_event_add_notifier(C, NC_WINDOW, NULL);
1287 /* makes button hilites work */
1288 WM_event_add_mousemove(C);
1292 /* only call outside of area/region loops */
1293 void ED_screen_set_scene(bContext *C, Scene *scene)
1296 bScreen *curscreen= CTX_wm_screen(C);
1298 for(sc= CTX_data_main(C)->screen.first; sc; sc= sc->id.next) {
1299 if((U.flag & USER_SCENEGLOBAL) || sc==curscreen) {
1301 if(scene != sc->scene) {
1302 /* all areas endlocalview */
1303 // XXX ScrArea *sa= sc->areabase.first;
1305 // endlocalview(sa);
1314 // copy_view3d_lock(0); /* space.c */
1316 /* are there cameras in the views that are not in the scene? */
1317 for(sc= CTX_data_main(C)->screen.first; sc; sc= sc->id.next) {
1318 if( (U.flag & USER_SCENEGLOBAL) || sc==curscreen) {
1319 ScrArea *sa= sc->areabase.first;
1321 SpaceLink *sl= sa->spacedata.first;
1323 if(sl->spacetype==SPACE_VIEW3D) {
1324 View3D *v3d= (View3D*) sl;
1325 if (!v3d->camera || !object_in_scene(v3d->camera, scene)) {
1326 v3d->camera= scene_find_camera(sc->scene);
1327 // XXX if (sc==curscreen) handle_view3d_lock();
1328 if (!v3d->camera && v3d->persp==V3D_CAMOB)
1329 v3d->persp= V3D_PERSP;
1339 CTX_data_scene_set(C, scene);
1340 set_scene_bg(scene);
1342 ED_update_for_newframe(C, 1);
1344 /* complete redraw */
1345 WM_event_add_notifier(C, NC_WINDOW, NULL);
1349 /* this function toggles: if area is full then the parent will be restored */
1350 void ed_screen_fullarea(bContext *C, ScrArea *sa)
1352 bScreen *sc, *oldscreen;
1360 sc= sa->full; /* the old screen to restore */
1361 oldscreen= CTX_wm_screen(C); /* the one disappearing */
1363 fulltype = sc->full;
1365 /* refuse to go out of SCREENAUTOPLAY as long as G_FLAGS_AUTOPLAY
1368 if (fulltype != SCREENAUTOPLAY || (G.flags & G_FILE_AUTOPLAY) == 0) {
1374 for(old= sc->areabase.first; old; old= old->next)
1375 if(old->full) break;
1377 printf("something wrong in areafullscreen\n");
1380 // old feature described below (ton)
1381 // in autoplay screens the headers are disabled by
1382 // default. So use the old headertype instead
1384 area_copy_data(old, sa, 1); /* 1 = swap spacelist */
1388 /* animtimer back */
1389 sc->animtimer= oldscreen->animtimer;
1390 oldscreen->animtimer= NULL;
1392 ED_screen_set(C, sc);
1394 free_screen(oldscreen);
1395 free_libblock(&CTX_data_main(C)->screen, oldscreen);
1401 oldscreen= CTX_wm_screen(C);
1403 /* is there only 1 area? */
1404 if(oldscreen->areabase.first==oldscreen->areabase.last) return;
1406 oldscreen->full = SCREENFULL;
1408 sc= ED_screen_add(CTX_wm_window(C), CTX_data_scene(C), "temp");
1409 sc->full = SCREENFULL; // XXX
1412 sc->animtimer= oldscreen->animtimer;
1413 oldscreen->animtimer= NULL;
1415 /* returns the top small area */
1416 newa= area_split(CTX_wm_window(C), sc, (ScrArea *)sc->areabase.first, 'h', 0.99f);
1417 ED_area_newspace(C, newa, SPACE_INFO);
1421 area_copy_data(newa, sa, 1); /* 1 = swap spacelist */
1423 sa->full= oldscreen;
1424 newa->full= oldscreen;
1425 newa->next->full= oldscreen; // XXX
1427 ED_screen_set(C, sc);
1430 /* XXX bad code: setscreen() ends with first area active. fullscreen render assumes this too */
1431 CTX_wm_area_set(C, sc->areabase.first);
1433 /* XXX retopo_force_update(); */
1437 int ED_screen_full_newspace(bContext *C, ScrArea *sa, int type)
1443 ed_screen_fullarea(C, sa);
1445 /* CTX_wm_area(C) is new area */
1446 ED_area_newspace(C, CTX_wm_area(C), type);
1451 void ED_screen_full_prevspace(bContext *C)
1453 ScrArea *sa= CTX_wm_area(C);
1455 ED_area_prevspace(C);
1458 ed_screen_fullarea(C, sa);
1461 /* redraws: uses defines from stime->redraws
1462 * enable: 1 - forward on, -1 - backwards on, 0 - off
1464 void ED_screen_animation_timer(bContext *C, int redraws, int enable)
1466 bScreen *screen= CTX_wm_screen(C);
1467 wmWindow *win= CTX_wm_window(C);
1468 Scene *scene= CTX_data_scene(C);
1470 if(screen->animtimer)
1471 WM_event_remove_window_timer(win, screen->animtimer);
1472 screen->animtimer= NULL;
1475 struct ScreenAnimData *sad= MEM_mallocN(sizeof(ScreenAnimData), "ScreenAnimData");
1477 screen->animtimer= WM_event_add_window_timer(win, TIMER0, (1.0/FPS));
1478 sad->ar= CTX_wm_region(C);
1479 sad->redraws= redraws;
1480 sad->reverse= (enable < 0);
1481 screen->animtimer->customdata= sad;
1484 /* notifier catched by top header, for button */
1485 WM_event_add_notifier(C, NC_SCREEN|ND_ANIMPLAY, screen);
1488 unsigned int ED_screen_view3d_layers(bScreen *screen)
1491 unsigned int layer= screen->scene->lay; /* as minimum this */
1494 /* get all used view3d layers */
1495 for(sa= screen->areabase.first; sa; sa= sa->next) {
1496 if(sa->spacetype==SPACE_VIEW3D)
1497 layer |= ((View3D *)sa->spacedata.first)->lay;
1505 /* results in fully updated anim system */
1506 /* in future sound should be on WM level, only 1 sound can play! */
1507 void ED_update_for_newframe(const bContext *C, int mute)
1509 bScreen *screen= CTX_wm_screen(C);
1510 Scene *scene= screen->scene;
1512 //extern void audiostream_scrub(unsigned int frame); /* seqaudio.c */
1514 /* this function applies the changes too */
1515 /* XXX future: do all windows */
1516 scene_update_for_newframe(scene, ED_screen_view3d_layers(screen)); /* BKE_scene.h */
1518 //if ( (CFRA>1) && (!mute) && (scene->audio.flag & AUDIO_SCRUB))
1519 // audiostream_scrub( CFRA );
1521 /* 3d window, preview */
1522 //BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
1524 /* all movie/sequence images */
1525 //BIF_image_update_frame();
1528 if(scene->use_nodes && scene->nodetree)
1529 ntreeCompositTagAnimated(scene->nodetree);
1531 /* update animated texture nodes */
1534 for(tex= CTX_data_main(C)->tex.first; tex; tex= tex->id.next)
1535 if( tex->use_nodes && tex->nodetree ) {
1536 ntreeTexTagAnimated( tex->nodetree );