commit before doing some hefty shapekey change, will break compilation
[blender-staging.git] / source / blender / editors / space_sequencer / space_sequencer.c
index 714e6be24167610f453a4fbf1ca7ee933c1db340..206070b7095e56404a08ec6cc48b9c530b9b6fb9 100644 (file)
@@ -41,8 +41,9 @@
 #include "BLI_rand.h"
 
 #include "BKE_colortools.h"
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
+#include "BKE_sequence.h"
 
 #include "ED_space_api.h"
 #include "ED_screen.h"
 
 #include "sequencer_intern.h"  // own include
 
+/* ******************** manage regions ********************* */
+
+ARegion *sequencer_has_buttons_region(ScrArea *sa)
+{
+       ARegion *ar, *arnew;
+       
+       for(ar= sa->regionbase.first; ar; ar= ar->next)
+               if(ar->regiontype==RGN_TYPE_UI)
+                       return ar;
+       
+       /* add subdiv level; after header */
+       for(ar= sa->regionbase.first; ar; ar= ar->next)
+               if(ar->regiontype==RGN_TYPE_HEADER)
+                       break;
+       
+       /* is error! */
+       if(ar==NULL) return NULL;
+       
+       arnew= MEM_callocN(sizeof(ARegion), "buttons for sequencer");
+       
+       BLI_insertlinkafter(&sa->regionbase, ar, arnew);
+       arnew->regiontype= RGN_TYPE_UI;
+       arnew->alignment= RGN_ALIGN_RIGHT;
+       
+       arnew->flag = RGN_FLAG_HIDDEN;
+       
+       return arnew;
+}
+
+
 /* ******************** default callbacks for sequencer space ***************** */
 
-static SpaceLink *sequencer_new(void)
+static SpaceLink *sequencer_new(const bContext *C)
 {
+       Scene *scene= CTX_data_scene(C);
        ARegion *ar;
        SpaceSeq *sseq;
        
@@ -80,6 +112,14 @@ static SpaceLink *sequencer_new(void)
        ar->regiontype= RGN_TYPE_HEADER;
        ar->alignment= RGN_ALIGN_BOTTOM;
        
+       /* buttons/list view */
+       ar= MEM_callocN(sizeof(ARegion), "buttons for sequencer");
+       
+       BLI_addtail(&sseq->regionbase, ar);
+       ar->regiontype= RGN_TYPE_UI;
+       ar->alignment= RGN_ALIGN_RIGHT;
+       ar->flag = RGN_FLAG_HIDDEN;
+       
        /* main area */
        ar= MEM_callocN(sizeof(ARegion), "main area for sequencer");
        
@@ -87,11 +127,11 @@ static SpaceLink *sequencer_new(void)
        ar->regiontype= RGN_TYPE_WINDOW;
        
        
-       /* seq space goes from (0,8) to (250, 0) */
+       /* seq space goes from (0,8) to (0, efra) */
        
        ar->v2d.tot.xmin= 0.0f;
        ar->v2d.tot.ymin= 0.0f;
-       ar->v2d.tot.xmax= 250.0f;
+       ar->v2d.tot.xmax= scene->r.efra;
        ar->v2d.tot.ymax= 8.0f;
        
        ar->v2d.cur= ar->v2d.tot;
@@ -109,8 +149,7 @@ static SpaceLink *sequencer_new(void)
        ar->v2d.scroll |= (V2D_SCROLL_LEFT|V2D_SCROLL_SCALE_VERTICAL);
        ar->v2d.keepzoom= 0;
        ar->v2d.keeptot= 0;
-       
-       
+       ar->v2d.align= V2D_ALIGN_NO_NEG_Y;
        
        return (SpaceLink *)sseq;
 }
@@ -146,80 +185,82 @@ static SpaceLink *sequencer_duplicate(SpaceLink *sl)
 /* add handlers, stuff you only do once or on area/region changes */
 static void sequencer_main_area_init(wmWindowManager *wm, ARegion *ar)
 {
-       ListBase *keymap;
+       wmKeyMap *keymap;
        
-       UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_TIMELINE, ar->winx, ar->winy);
+       UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
        
        /* own keymap */
-       keymap= WM_keymap_listbase(wm, "Sequencer", SPACE_SEQ, 0);      /* XXX weak? */
+       keymap= WM_keymap_find(wm->defaultconf, "Sequencer", SPACE_SEQ, 0);
        WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
 }
 
-static void sequencer_main_area_draw(const bContext *C, ARegion *ar)
+
+/* add handlers, stuff you only do once or on area/region changes */
+static void sequencer_header_area_init(wmWindowManager *wm, ARegion *ar)
 {
-       /* draw entirely, view changes should be handled here */
-       // SpaceSeq *sseq= C->area->spacedata.first;
-       View2D *v2d= &ar->v2d;
-       float col[3];
-       
-       /* clear and setup matrix */
-       UI_GetThemeColor3fv(TH_BACK, col);
-       glClearColor(col[0], col[1], col[2], 0.0);
-       glClear(GL_COLOR_BUFFER_BIT);
-       
-       UI_view2d_view_ortho(C, v2d);
-               
-       /* data... */
-       
-       
-       /* reset view matrix */
-       UI_view2d_view_restore(C);
-       
-       /* scrollers? */
+       ED_region_header_init(ar);
 }
 
-void sequencer_operatortypes(void)
+static void sequencer_header_area_draw(const bContext *C, ARegion *ar)
 {
-       
+       ED_region_header(C, ar);
 }
 
-void sequencer_keymap(struct wmWindowManager *wm)
+static void sequencer_main_area_listener(ARegion *ar, wmNotifier *wmn)
 {
-       
+       /* context changes */
+       switch(wmn->category) {
+               case NC_SCENE:
+                       switch(wmn->data) {
+                               case ND_FRAME:
+                               case ND_MARKERS:
+                               case ND_SEQUENCER:
+                                       ED_region_tag_redraw(ar);
+                                       break;
+                       }
+                       break;
+               case NC_SPACE:
+                       if(wmn->data == ND_SPACE_SEQUENCER)
+                               ED_region_tag_redraw(ar);
+                       break;
+       }
 }
 
+/* *********************** buttons region ************************ */
+
 /* add handlers, stuff you only do once or on area/region changes */
-static void sequencer_header_area_init(wmWindowManager *wm, ARegion *ar)
+static void sequencer_buttons_area_init(wmWindowManager *wm, ARegion *ar)
 {
-       UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
+       
+       ED_region_panels_init(wm, ar);
+       
 }
 
-static void sequencer_header_area_draw(const bContext *C, ARegion *ar)
+static void sequencer_buttons_area_draw(const bContext *C, ARegion *ar)
 {
-       float col[3];
-       
-       /* clear */
-       if(ED_screen_area_active(C))
-               UI_GetThemeColor3fv(TH_HEADER, col);
-       else
-               UI_GetThemeColor3fv(TH_HEADERDESEL, col);
-       
-       glClearColor(col[0], col[1], col[2], 0.0);
-       glClear(GL_COLOR_BUFFER_BIT);
-       
-       /* set view2d view matrix for scrolling (without scrollers) */
-       UI_view2d_view_ortho(C, &ar->v2d);
-       
-       sequencer_header_buttons(C, ar);
-       
-       /* restore view matrix? */
-       UI_view2d_view_restore(C);
+       ED_region_panels(C, ar, 1, NULL, -1);
 }
 
-static void sequencer_main_area_listener(ARegion *ar, wmNotifier *wmn)
+static void sequencer_buttons_area_listener(ARegion *ar, wmNotifier *wmn)
 {
        /* context changes */
+       switch(wmn->category) {
+               case NC_SCENE:
+               switch(wmn->data) {
+                       case ND_FRAME:
+                       case ND_SEQUENCER:
+                               ED_region_tag_redraw(ar);
+                               break;
+               }
+               break;
+               case NC_SPACE:
+                       if(wmn->data == ND_SPACE_SEQUENCER)
+                               ED_region_tag_redraw(ar);
+                       break;
+               
+       }
 }
+/* ************************************* */
 
 /* only called once, from space/spacetypes.c */
 void ED_spacetype_sequencer(void)
@@ -240,24 +281,38 @@ void ED_spacetype_sequencer(void)
        art= MEM_callocN(sizeof(ARegionType), "spacetype sequencer region");
        art->regionid = RGN_TYPE_WINDOW;
        art->init= sequencer_main_area_init;
-       art->draw= sequencer_main_area_draw;
+       art->draw= drawseqspace;
        art->listener= sequencer_main_area_listener;
-       art->keymapflag= ED_KEYMAP_VIEW2D;
+       art->keymapflag= ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES;
 
        BLI_addhead(&st->regiontypes, art);
        
+       /* regions: listview/buttons */
+       art= MEM_callocN(sizeof(ARegionType), "spacetype sequencer region");
+       art->regionid = RGN_TYPE_UI;
+       art->minsizex= 220; // XXX
+       art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_FRAMES;
+       art->listener= sequencer_buttons_area_listener;
+       art->init= sequencer_buttons_area_init;
+       art->draw= sequencer_buttons_area_draw;
+       BLI_addhead(&st->regiontypes, art);
+       
+       /* Keep as python only for now
+       sequencer_buttons_register(art);
+       */
+
        /* regions: header */
        art= MEM_callocN(sizeof(ARegionType), "spacetype sequencer region");
        art->regionid = RGN_TYPE_HEADER;
        art->minsizey= HEADERY;
-       art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
+       art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES;
        
        art->init= sequencer_header_area_init;
        art->draw= sequencer_header_area_draw;
+       art->listener= sequencer_main_area_listener;
        
        BLI_addhead(&st->regiontypes, art);
        
-       
        BKE_spacetype_register(st);
 }