2.5
[blender.git] / source / blender / editors / space_ipo / space_ipo.c
index 811d29dba145ac456fba2ba74cb4e6d23d4890fc..99b0ebcf03c2b1a7bd18e43bbfd6ad8ce7373983 100644 (file)
 #include "BLI_arithb.h"
 #include "BLI_rand.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_space_api.h"
 #include "ED_screen.h"
+#include "ED_anim_api.h"
+#include "ED_markers.h"
 
 #include "BIF_gl.h"
 
 #include "UI_resources.h"
 #include "UI_view2d.h"
 
-#include "ED_markers.h"
-
 #include "ipo_intern.h"        // own include
 
 /* ******************** default callbacks for ipo space ***************** */
 
-static SpaceLink *ipo_new(void)
+static SpaceLink *ipo_new(const bContext *C)
 {
+       Scene *scene= CTX_data_scene(C);
        ARegion *ar;
        SpaceIpo *sipo;
        
@@ -77,14 +78,15 @@ static SpaceLink *ipo_new(void)
        BLI_addtail(&sipo->regionbase, ar);
        ar->regiontype= RGN_TYPE_HEADER;
        ar->alignment= RGN_ALIGN_BOTTOM;
-       UI_view2d_header_default(&ar->v2d);
        
        /* channels */
        ar= MEM_callocN(sizeof(ARegion), "main area for ipo");
        
        BLI_addtail(&sipo->regionbase, ar);
        ar->regiontype= RGN_TYPE_CHANNELS;
-       ar->alignment= RGN_ALIGN_RIGHT;
+       ar->alignment= RGN_ALIGN_LEFT;
+       
+       ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
        
        /* XXX view2d init for channels */
        
@@ -96,7 +98,7 @@ static SpaceLink *ipo_new(void)
        
        ar->v2d.tot.xmin= 0.0f;
        ar->v2d.tot.ymin= -10.0f;
-       ar->v2d.tot.xmax= 250.0;
+       ar->v2d.tot.xmax= scene->r.efra;
        ar->v2d.tot.ymax= 10.0f;
        
        ar->v2d.cur= ar->v2d.tot;
@@ -105,10 +107,10 @@ static SpaceLink *ipo_new(void)
        ar->v2d.min[1]= 0.01f;
        
        ar->v2d.max[0]= MAXFRAMEF;
-       ar->v2d.max[1]= 10000.0f;
+       ar->v2d.max[1]= 50000.0f;
        
-       ar->v2d.scroll= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_BOTTOM);
-       ar->v2d.scroll |= (V2D_SCROLL_LEFT|V2D_SCROLL_SCALE_LEFT);
+       ar->v2d.scroll= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
+       ar->v2d.scroll |= (V2D_SCROLL_LEFT|V2D_SCROLL_SCALE_VERTICAL);
        
        ar->v2d.keeptot= 0;
        
@@ -151,7 +153,7 @@ static void ipo_main_area_init(wmWindowManager *wm, ARegion *ar)
 {
        ListBase *keymap;
        
-       UI_view2d_size_update(&ar->v2d, ar->winx, ar->winy);
+       UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
        
        /* own keymap */
        keymap= WM_keymap_listbase(wm, "Ipo", SPACE_IPO, 0);    /* XXX weak? */
@@ -161,12 +163,12 @@ static void ipo_main_area_init(wmWindowManager *wm, ARegion *ar)
 static void ipo_main_area_draw(const bContext *C, ARegion *ar)
 {
        /* draw entirely, view changes should be handled here */
-       SpaceIpo *sipo= C->area->spacedata.first;
+       SpaceIpo *sipo= (SpaceIpo*)CTX_wm_space_data(C);
        View2D *v2d= &ar->v2d;
        View2DGrid *grid;
        View2DScrollers *scrollers;
        float col[3];
-       int unit;
+       short unit=0, flag=0;
        
        /* clear and setup matrix */
        UI_GetThemeColor3fv(TH_BACK, col);
@@ -176,20 +178,32 @@ static void ipo_main_area_draw(const bContext *C, ARegion *ar)
        UI_view2d_view_ortho(C, v2d);
        
        /* grid */
-       unit= (sipo->flag & TIME_DRAWFRAMES)? V2D_UNIT_FRAMES: V2D_UNIT_SECONDS;
-       grid= UI_view2d_grid_calc(C, v2d, unit, V2D_GRID_CLAMP, ar->winx, ar->winy);
-       UI_view2d_grid_draw(C, v2d, grid, (V2D_VERTICAL_LINES|V2D_VERTICAL_AXIS));
+       unit= (sipo->flag & SIPO_DRAWTIME)? V2D_UNIT_SECONDS : V2D_UNIT_FRAMES;
+       grid= UI_view2d_grid_calc(C, v2d, unit, V2D_GRID_NOCLAMP, V2D_UNIT_VALUES/*unit-y*/, V2D_GRID_NOCLAMP, ar->winx, ar->winy);
+       UI_view2d_grid_draw(C, v2d, grid, V2D_GRIDLINES_ALL);
        UI_view2d_grid_free(grid);
-               
+       
+       /* data... */
+       
+       /* current frame */
+       if (sipo->flag & SIPO_DRAWTIME)         flag |= DRAWCFRA_UNIT_SECONDS;
+       if ((sipo->flag & SIPO_NODRAWCFRANUM)==0)  flag |= DRAWCFRA_SHOW_NUMBOX;
+       ANIM_draw_cfra(C, v2d, flag);
+       
        /* markers */
        UI_view2d_view_orthoSpecial(C, v2d, 1);
        draw_markers_time(C, 0);
        
+       /* preview range */
+       UI_view2d_view_ortho(C, v2d);
+       ANIM_draw_previewrange(C, v2d);
+       
        /* reset view matrix */
        UI_view2d_view_restore(C);
        
        /* scrollers */
-       scrollers= UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
+               // FIXME: args for scrollers depend on the type of data being shown...
+       scrollers= UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_NOCLAMP, V2D_UNIT_VALUES/*unit-y*/, V2D_GRID_NOCLAMP);
        UI_view2d_scrollers_draw(C, v2d, scrollers);
        UI_view2d_scrollers_free(scrollers);
 }
@@ -202,10 +216,40 @@ void ipo_keymap(struct wmWindowManager *wm)
 {
 }
 
+static void ipo_channel_area_init(wmWindowManager *wm, ARegion *ar)
+{
+       UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
+}
+
+static void ipo_channel_area_draw(const bContext *C, ARegion *ar)
+{
+       //SpaceIpo *sipo= C->area->spacedata.first;
+       View2D *v2d= &ar->v2d;
+       View2DScrollers *scrollers;
+       float col[3];
+       
+       /* clear and setup matrix */
+       UI_GetThemeColor3fv(TH_SHADE2, 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 */
+       scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
+       UI_view2d_scrollers_draw(C, v2d, scrollers);
+       UI_view2d_scrollers_free(scrollers);
+}
+
 /* add handlers, stuff you only do once or on area/region changes */
 static void ipo_header_area_init(wmWindowManager *wm, ARegion *ar)
 {
-       UI_view2d_size_update(&ar->v2d, ar->winx, ar->winy);
+       UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
 }
 
 static void ipo_header_area_draw(const bContext *C, ARegion *ar)
@@ -233,12 +277,18 @@ static void ipo_header_area_draw(const bContext *C, ARegion *ar)
 static void ipo_main_area_listener(ARegion *ar, wmNotifier *wmn)
 {
        /* context changes */
+       switch(wmn->type) {
+               
+               case WM_NOTE_MARKERS_CHANGED:
+                       ED_region_tag_redraw(ar);
+                       break;
+       }
 }
 
 /* only called once, from space/spacetypes.c */
 void ED_spacetype_ipo(void)
 {
-       SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype time");
+       SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype ipo");
        ARegionType *art;
        
        st->spaceid= SPACE_IPO;
@@ -251,16 +301,17 @@ void ED_spacetype_ipo(void)
        st->keymap= ipo_keymap;
        
        /* regions: main window */
-       art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
+       art= MEM_callocN(sizeof(ARegionType), "spacetype ipo region");
        art->regionid = RGN_TYPE_WINDOW;
        art->init= ipo_main_area_init;
        art->draw= ipo_main_area_draw;
        art->listener= ipo_main_area_listener;
+       art->keymapflag= ED_KEYMAP_VIEW2D|ED_KEYMAP_MARKERS|ED_KEYMAP_ANIMATION;
 
        BLI_addhead(&st->regiontypes, art);
        
        /* regions: header */
-       art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
+       art= MEM_callocN(sizeof(ARegionType), "spacetype ipo region");
        art->regionid = RGN_TYPE_HEADER;
        art->minsizey= HEADERY;
        art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
@@ -271,13 +322,13 @@ void ED_spacetype_ipo(void)
        BLI_addhead(&st->regiontypes, art);
        
        /* regions: channels */
-       art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
+       art= MEM_callocN(sizeof(ARegionType), "spacetype ipo region");
        art->regionid = RGN_TYPE_CHANNELS;
-       art->minsizex= 80;
+       art->minsizex= 200;
        art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
        
-//     art->init= ipo_channel_area_init;
-//     art->draw= ipo_channel_area_draw;
+       art->init= ipo_channel_area_init;
+       art->draw= ipo_channel_area_draw;
        
        BLI_addhead(&st->regiontypes, art);