2.5 audio cleanup:
[blender.git] / source / blender / editors / screen / screen_edit.c
index 800a618e89e7c69d06038249127953562e3a30dd..5519b2609a1494dda08edc354fee7278d5fcafa9 100644 (file)
@@ -32,6 +32,7 @@
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_texture_types.h"
+#include "DNA_userdef_types.h"
 
 #include "BLI_blenlib.h"
 
@@ -53,6 +54,7 @@
 #include "ED_screen.h"
 #include "ED_screen_types.h"
 
+/* XXX actually should be not here... solve later */
 #include "wm_subwindow.h"
 
 #include "screen_intern.h"     /* own module include */
@@ -403,7 +405,7 @@ ScrArea *area_split(wmWindow *win, bScreen *sc, ScrArea *sa, char dir, float fac
 
 /* empty screen, with 1 dummy area without spacedata */
 /* uses window size */
-bScreen *screen_add(wmWindow *win, Scene *scene, char *name)
+bScreen *ED_screen_add(wmWindow *win, Scene *scene, char *name)
 {
        bScreen *sc;
        ScrVert *sv1, *sv2, *sv3, *sv4;
@@ -464,7 +466,6 @@ static void screen_copy(bScreen *to, bScreen *from)
                sa->spacedata.first= sa->spacedata.last= NULL;
                sa->regionbase.first= sa->regionbase.last= NULL;
                sa->actionzones.first= sa->actionzones.last= NULL;
-               sa->scriptlink.totscript= 0;
                
                area_copy_data(sa, saf, 0);
        }
@@ -867,32 +868,49 @@ static void scrarea_draw_shape_light(ScrArea *sa, char dir)
        glDisable(GL_BLEND);
 }
 
-/** screen edges drawing **/
-static void drawscredge_area(ScrArea *sa)
+static void drawscredge_area_draw(int sizex, int sizey, short x1, short y1, short x2, short y2, short a) 
 {
-       short x1= sa->v1->vec.x;
-       short y1= sa->v1->vec.y;
-       short x2= sa->v3->vec.x;
-       short y2= sa->v3->vec.y;
-       
-       cpack(0x0);
-       
        /* right border area */
-       sdrawline(x2, y1, x2, y2);
+       if(x2<sizex-1)
+               sdrawline(x2+a, y1, x2+a, y2);
        
        /* left border area */
-       if(x1>0) { /* otherwise it draws the emboss of window over */
-               sdrawline(x1, y1, x1, y2);
-       }
+       if(x1>0)  /* otherwise it draws the emboss of window over */
+               sdrawline(x1+a, y1, x1+a, y2);
        
        /* top border area */
-       sdrawline(x1, y2, x2, y2);
+       if(y2<sizey-1)
+               sdrawline(x1, y2+a, x2, y2+a);
        
        /* bottom border area */
-       sdrawline(x1, y1, x2, y1);
+       if(y1>0)
+               sdrawline(x1, y1+a, x2, y1+a);
        
 }
 
+/** screen edges drawing **/
+static void drawscredge_area(ScrArea *sa, int sizex, int sizey, int center)
+{
+       short x1= sa->v1->vec.x;
+       short y1= sa->v1->vec.y;
+       short x2= sa->v3->vec.x;
+       short y2= sa->v3->vec.y;
+       short a, rt;
+       
+       rt= CLAMPIS(G.rt, 0, 16);
+       
+       if(center==0) {
+               cpack(0x505050);
+               for(a=-rt; a<=rt; a++)
+                       if(a!=0)
+                               drawscredge_area_draw(sizex, sizey, x1, y1, x2, y2, a);
+       }
+       else {
+               cpack(0x0);
+               drawscredge_area_draw(sizex, sizey, x1, y1, x2, y2, 0);
+       }
+}
+
 /* ****************** EXPORTED API TO OTHER MODULES *************************** */
 
 bScreen *ED_screen_duplicate(wmWindow *win, bScreen *sc)
@@ -902,7 +920,7 @@ bScreen *ED_screen_duplicate(wmWindow *win, bScreen *sc)
        if(sc->full != SCREENNORMAL) return NULL; /* XXX handle this case! */
        
        /* make new empty screen: */
-       newsc= screen_add(win, sc->scene, sc->id.name+2);
+       newsc= ED_screen_add(win, sc->scene, sc->id.name+2);
        /* copy all data */
        screen_copy(newsc, sc);
        /* set in window */
@@ -970,9 +988,11 @@ void ED_screen_draw(wmWindow *win)
        for(sa= win->screen->areabase.first; sa; sa= sa->next) {
                if (sa->flag & AREA_FLAG_DRAWJOINFROM) sa1 = sa;
                if (sa->flag & AREA_FLAG_DRAWJOINTO) sa2 = sa;
-               drawscredge_area(sa);
+               drawscredge_area(sa, win->sizex, win->sizey, 0);
        }
-
+       for(sa= win->screen->areabase.first; sa; sa= sa->next)
+               drawscredge_area(sa, win->sizex, win->sizey, 1);
+       
        /* blended join arrow */
        if (sa1 && sa2) {
                dir = area_getorientation(win->screen, sa1, sa2);
@@ -1115,14 +1135,22 @@ void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
 /* case when on area-edge or in azones, or outside window */
 static void screen_cursor_set(wmWindow *win, wmEvent *event)
 {
+       AZone *az= NULL;
        ScrArea *sa;
        
        for(sa= win->screen->areabase.first; sa; sa= sa->next)
-               if(is_in_area_actionzone(sa, event->x, event->y))
+               if((az=is_in_area_actionzone(sa, event->x, event->y)))
                        break;
        
        if(sa) {
-               WM_cursor_set(win, CURSOR_EDIT);
+               if(az->type==AZONE_AREA)
+                       WM_cursor_set(win, CURSOR_EDIT);
+               else if(az->type==AZONE_REGION) {
+                       if(az->x1==az->x2)
+                               WM_cursor_set(win, CURSOR_X_MOVE);
+                       else
+                               WM_cursor_set(win, CURSOR_Y_MOVE);
+               }
        }
        else {
                ScrEdge *actedge= screen_find_active_scredge(win->screen, event->x, event->y);
@@ -1234,7 +1262,6 @@ void ED_screen_set(bContext *C, bScreen *sc)
                                break;
                        }
                }
-               if(sc1==NULL) printf("set screen error\n");
        }
        
        if (oldscreen != sc) {
@@ -1256,9 +1283,69 @@ void ED_screen_set(bContext *C, bScreen *sc)
                
                ED_screen_refresh(CTX_wm_manager(C), CTX_wm_window(C));
                WM_event_add_notifier(C, NC_WINDOW, NULL);
+               
+               /* makes button hilites work */
+               WM_event_add_mousemove(C);
        }
 }
 
+/* only call outside of area/region loops */
+void ED_screen_set_scene(bContext *C, Scene *scene)
+{
+       bScreen *sc;
+       bScreen *curscreen= CTX_wm_screen(C);
+       
+       for(sc= CTX_data_main(C)->screen.first; sc; sc= sc->id.next) {
+               if((U.flag & USER_SCENEGLOBAL) || sc==curscreen) {
+                       
+                       if(scene != sc->scene) {
+                               /* all areas endlocalview */
+                       // XXX  ScrArea *sa= sc->areabase.first;
+                       //      while(sa) {
+                       //              endlocalview(sa);
+                       //              sa= sa->next;
+                       //      }               
+                               sc->scene= scene;
+                       }
+                       
+               }
+       }
+       
+       //  copy_view3d_lock(0);        /* space.c */
+       
+       /* are there cameras in the views that are not in the scene? */
+       for(sc= CTX_data_main(C)->screen.first; sc; sc= sc->id.next) {
+               if( (U.flag & USER_SCENEGLOBAL) || sc==curscreen) {
+                       ScrArea *sa= sc->areabase.first;
+                       while(sa) {
+                               SpaceLink *sl= sa->spacedata.first;
+                               while(sl) {
+                                       if(sl->spacetype==SPACE_VIEW3D) {
+                                               View3D *v3d= (View3D*) sl;
+                                               if (!v3d->camera || !object_in_scene(v3d->camera, scene)) {
+                                                       v3d->camera= scene_find_camera(sc->scene);
+                                                       // XXX if (sc==curscreen) handle_view3d_lock();
+                                                       if (!v3d->camera && v3d->persp==V3D_CAMOB) 
+                                                               v3d->persp= V3D_PERSP;
+                                               }
+                                       }
+                                       sl= sl->next;
+                               }
+                               sa= sa->next;
+                       }
+               }
+       }
+       
+       CTX_data_scene_set(C, scene);
+       set_scene_bg(scene);
+       
+       ED_update_for_newframe(C, 1);
+       
+       /* complete redraw */
+       WM_event_add_notifier(C, NC_WINDOW, NULL);
+       
+}
+
 /* this function toggles: if area is full then the parent will be restored */
 void ed_screen_fullarea(bContext *C, ScrArea *sa)
 {
@@ -1305,7 +1392,7 @@ void ed_screen_fullarea(bContext *C, ScrArea *sa)
                        ED_screen_set(C, sc);
                        
                        free_screen(oldscreen);
-                       free_libblock(&G.main->screen, oldscreen);
+                       free_libblock(&CTX_data_main(C)->screen, oldscreen);
                }
        }
        else {
@@ -1315,11 +1402,10 @@ void ed_screen_fullarea(bContext *C, ScrArea *sa)
 
                /* is there only 1 area? */
                if(oldscreen->areabase.first==oldscreen->areabase.last) return;
-               if(sa->spacetype==SPACE_INFO) return;
                
                oldscreen->full = SCREENFULL;
                
-               sc= screen_add(CTX_wm_window(C), CTX_data_scene(C), "temp");
+               sc= ED_screen_add(CTX_wm_window(C), CTX_data_scene(C), "temp");
                sc->full = SCREENFULL; // XXX
                
                /* timer */
@@ -1348,13 +1434,18 @@ void ed_screen_fullarea(bContext *C, ScrArea *sa)
 
 }
 
-void ED_screen_full_newspace(bContext *C, ScrArea *sa, int type)
+int ED_screen_full_newspace(bContext *C, ScrArea *sa, int type)
 {
+       if(sa==NULL)
+               return 0;
+       
        if(sa->full==0)
                ed_screen_fullarea(C, sa);
 
        /* CTX_wm_area(C) is new area */
        ED_area_newspace(C, CTX_wm_area(C), type);
+       
+       return 1;
 }
 
 void ED_screen_full_prevspace(bContext *C)
@@ -1367,7 +1458,10 @@ void ED_screen_full_prevspace(bContext *C)
                ed_screen_fullarea(C, sa);
 }
 
-void ED_screen_animation_timer(bContext *C, int enable)
+/* redraws: uses defines from stime->redraws 
+ * enable: 1 - forward on, -1 - backwards on, 0 - off
+ */
+void ED_screen_animation_timer(bContext *C, int redraws, int enable)
 {
        bScreen *screen= CTX_wm_screen(C);
        wmWindow *win= CTX_wm_window(C);
@@ -1377,8 +1471,18 @@ void ED_screen_animation_timer(bContext *C, int enable)
                WM_event_remove_window_timer(win, screen->animtimer);
        screen->animtimer= NULL;
        
-       if(enable)
+       if(enable) {
+               struct ScreenAnimData *sad= MEM_mallocN(sizeof(ScreenAnimData), "ScreenAnimData");
+               
                screen->animtimer= WM_event_add_window_timer(win, TIMER0, (1.0/FPS));
+               sad->ar= CTX_wm_region(C);
+               sad->redraws= redraws;
+               sad->flag= (enable < 0) ? ANIMPLAY_FLAG_REVERSE : 0;
+               screen->animtimer->customdata= sad;
+               
+       }
+       /* notifier catched by top header, for button */
+       WM_event_add_notifier(C, NC_SCREEN|ND_ANIMPLAY, screen);
 }
 
 unsigned int ED_screen_view3d_layers(bScreen *screen)
@@ -1399,7 +1503,6 @@ unsigned int ED_screen_view3d_layers(bScreen *screen)
 
 
 /* results in fully updated anim system */
-/* in future sound should be on WM level, only 1 sound can play! */
 void ED_update_for_newframe(const bContext *C, int mute)
 {
        bScreen *screen= CTX_wm_screen(C);
@@ -1427,7 +1530,7 @@ void ED_update_for_newframe(const bContext *C, int mute)
        /* update animated texture nodes */
        {
                Tex *tex;
-               for(tex= G.main->tex.first; tex; tex= tex->id.next)
+               for(tex= CTX_data_main(C)->tex.first; tex; tex= tex->id.next)
                        if( tex->use_nodes && tex->nodetree ) {
                                ntreeTexTagAnimated( tex->nodetree );
                        }