merge outliner refactor so we dont have to keep outliner.c locked in trunk.
[blender.git] / source / blender / editors / space_time / space_time.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
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. 
10  *
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.
15  *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 /** \file blender/editors/space_time/space_time.c
30  *  \ingroup sptime
31  */
32
33
34 #include <string.h>
35 #include <stdio.h>
36
37 #include "DNA_object_types.h"
38 #include "DNA_scene_types.h"
39
40 #include "MEM_guardedalloc.h"
41
42 #include "BLI_blenlib.h"
43 #include "BLI_dlrbTree.h"
44 #include "BLI_utildefines.h"
45
46 #include "BKE_context.h"
47 #include "BKE_global.h"
48 #include "BKE_screen.h"
49 #include "BKE_pointcache.h"
50
51 #include "ED_anim_api.h"
52 #include "ED_keyframes_draw.h"
53 #include "ED_screen.h"
54
55 #include "WM_api.h"
56 #include "WM_types.h"
57
58 #include "BIF_gl.h"
59 #include "BIF_glutil.h"
60
61 #include "UI_resources.h"
62 #include "UI_view2d.h"
63
64 #include "ED_space_api.h"
65 #include "ED_markers.h"
66
67 #include "time_intern.h"
68
69 /* ************************ main time area region *********************** */
70
71 static void time_draw_sfra_efra(Scene *scene, View2D *v2d)
72 {       
73         /* draw darkened area outside of active timeline 
74          * frame range used is preview range or scene range */
75         UI_ThemeColorShade(TH_BACK, -25);
76
77         if (PSFRA < PEFRA) {
78                 glRectf(v2d->cur.xmin, v2d->cur.ymin, (float)PSFRA, v2d->cur.ymax);
79                 glRectf((float)PEFRA, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
80         }
81         else {
82                 glRectf(v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
83         }
84
85         UI_ThemeColorShade(TH_BACK, -60);
86         /* thin lines where the actual frames are */
87         fdrawline((float)PSFRA, v2d->cur.ymin, (float)PSFRA, v2d->cur.ymax);
88         fdrawline((float)PEFRA, v2d->cur.ymin, (float)PEFRA, v2d->cur.ymax);
89 }
90
91 #define CACHE_DRAW_HEIGHT       3.0f
92
93 static void time_draw_cache(SpaceTime *stime, Object *ob)
94 {
95         PTCacheID *pid;
96         ListBase pidlist;
97         SpaceTimeCache *stc = stime->caches.first;
98         float yoffs=0.f;
99         
100         if (!(stime->cache_display & TIME_CACHE_DISPLAY) || (!ob))
101                 return;
102
103         BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0);
104
105         /* iterate over pointcaches on the active object, 
106          * add spacetimecache and vertex array for each */
107         for(pid=pidlist.first; pid; pid=pid->next) {
108                 float col[4], *fp;
109                 int i, sta = pid->cache->startframe, end = pid->cache->endframe;
110                 int len = (end - sta + 1)*4;
111
112                 switch(pid->type) {
113                         case PTCACHE_TYPE_SOFTBODY:
114                                 if (!(stime->cache_display & TIME_CACHE_SOFTBODY)) continue;
115                                 break;
116                         case PTCACHE_TYPE_PARTICLES:
117                                 if (!(stime->cache_display & TIME_CACHE_PARTICLES))     continue;
118                                 break;
119                         case PTCACHE_TYPE_CLOTH:
120                                 if (!(stime->cache_display & TIME_CACHE_CLOTH)) continue;
121                                 break;
122                         case PTCACHE_TYPE_SMOKE_DOMAIN:
123                         case PTCACHE_TYPE_SMOKE_HIGHRES:
124                                 if (!(stime->cache_display & TIME_CACHE_SMOKE)) continue;
125                                 break;
126                 }
127
128                 if(pid->cache->cached_frames == NULL)
129                         continue;
130
131
132                 /* make sure we have stc with correct array length */
133                 if(stc == NULL || MEM_allocN_len(stc->array) != len*2*sizeof(float)) {
134                         if(stc) {
135                                 MEM_freeN(stc->array);
136                         }
137                         else {
138                                 stc = MEM_callocN(sizeof(SpaceTimeCache), "spacetimecache");
139                                 BLI_addtail(&stime->caches, stc);
140                         }
141
142                         stc->array = MEM_callocN(len*2*sizeof(float), "SpaceTimeCache array");
143                 }
144
145                 /* fill the vertex array with a quad for each cached frame */
146                 for (i=sta, fp=stc->array; i<=end; i++) {
147                         if (pid->cache->cached_frames[i-sta]) {
148                                 fp[0] = (float)i-0.5f;
149                                 fp[1] = 0.0;
150                                 fp+=2;
151                                 
152                                 fp[0] = (float)i-0.5f;
153                                 fp[1] = 1.0;
154                                 fp+=2;
155                                 
156                                 fp[0] = (float)i+0.5f;
157                                 fp[1] = 1.0;
158                                 fp+=2;
159                                 
160                                 fp[0] = (float)i+0.5f;
161                                 fp[1] = 0.0;
162                                 fp+=2;
163                         }
164                 }
165                 
166                 glPushMatrix();
167                 glTranslatef(0.0, (float)V2D_SCROLL_HEIGHT+yoffs, 0.0);
168                 glScalef(1.0, CACHE_DRAW_HEIGHT, 0.0);
169                 
170                 switch(pid->type) {
171                         case PTCACHE_TYPE_SOFTBODY:
172                                 col[0] = 1.0;   col[1] = 0.4;   col[2] = 0.02;
173                                 col[3] = 0.1;
174                                 break;
175                         case PTCACHE_TYPE_PARTICLES:
176                                 col[0] = 1.0;   col[1] = 0.1;   col[2] = 0.02;
177                                 col[3] = 0.1;
178                                 break;
179                         case PTCACHE_TYPE_CLOTH:
180                                 col[0] = 0.1;   col[1] = 0.1;   col[2] = 0.75;
181                                 col[3] = 0.1;
182                                 break;
183                         case PTCACHE_TYPE_SMOKE_DOMAIN:
184                         case PTCACHE_TYPE_SMOKE_HIGHRES:
185                                 col[0] = 0.2;   col[1] = 0.2;   col[2] = 0.2;
186                                 col[3] = 0.1;
187                                 break;
188                 }
189                 glColor4fv(col);
190                 
191                 glEnable(GL_BLEND);
192                 
193                 glRectf((float)sta, 0.0, (float)end, 1.0);
194                 
195                 col[3] = 0.4f;
196                 if (pid->cache->flag & PTCACHE_BAKED) {
197                         col[0] -= 0.4f; col[1] -= 0.4f; col[2] -= 0.4f;
198                 }
199                 glColor4fv(col);
200                 
201                 glEnableClientState(GL_VERTEX_ARRAY);
202                 glVertexPointer(2, GL_FLOAT, 0, stc->array);
203                 glDrawArrays(GL_QUADS, 0, (fp-stc->array)/2);
204                 glDisableClientState(GL_VERTEX_ARRAY);
205                 
206                 glDisable(GL_BLEND);
207                 
208                 glPopMatrix();
209                 
210                 yoffs += CACHE_DRAW_HEIGHT;
211
212                 stc = stc->next;
213         }
214
215         BLI_freelistN(&pidlist);
216
217         /* free excessive caches */
218         while(stc) {
219                 SpaceTimeCache *tmp = stc->next;
220                 BLI_remlink(&stime->caches, stc);
221                 MEM_freeN(stc->array);
222                 MEM_freeN(stc);
223                 stc = tmp;
224         }
225 }
226
227 static void time_cache_free(SpaceTime *stime)
228 {
229         SpaceTimeCache *stc;
230         
231         for (stc= stime->caches.first; stc; stc=stc->next) {
232                 if (stc->array) {
233                         MEM_freeN(stc->array);
234                         stc->array = NULL;
235                 }
236         }
237         
238         BLI_freelistN(&stime->caches);
239 }
240
241 static void time_cache_refresh(SpaceTime *stime)
242 {
243         /* Free previous caches to indicate full refresh */
244         time_cache_free(stime);
245 }
246
247 /* helper function - find actkeycolumn that occurs on cframe, or the nearest one if not found */
248 static ActKeyColumn *time_cfra_find_ak (ActKeyColumn *ak, float cframe)
249 {
250         ActKeyColumn *akn= NULL;
251         
252         /* sanity checks */
253         if (ak == NULL)
254                 return NULL;
255         
256         /* check if this is a match, or whether it is in some subtree */
257         if (cframe < ak->cfra)
258                 akn= time_cfra_find_ak(ak->left, cframe);
259         else if (cframe > ak->cfra)
260                 akn= time_cfra_find_ak(ak->right, cframe);
261                 
262         /* if no match found (or found match), just use the current one */
263         if (akn == NULL)
264                 return ak;
265         else
266                 return akn;
267 }
268
269 /* helper for time_draw_keyframes() */
270 static void time_draw_idblock_keyframes(View2D *v2d, ID *id, short onlysel)
271 {
272         bDopeSheet ads= {NULL};
273         DLRBT_Tree keys;
274         ActKeyColumn *ak;
275         
276         /* init binarytree-list for getting keyframes */
277         BLI_dlrbTree_init(&keys);
278         
279         /* init dopesheet settings */
280         // FIXME: the ob_to_keylist function currently doesn't take this into account...
281         if (onlysel)
282                 ads.filterflag |= ADS_FILTER_ONLYSEL;
283         
284         /* populate tree with keyframe nodes */
285         switch (GS(id->name)) {
286                 case ID_SCE:
287                         scene_to_keylist(&ads, (Scene *)id, &keys, NULL);
288                         break;
289                 case ID_OB:
290                         ob_to_keylist(&ads, (Object *)id, &keys, NULL);
291                         break;
292         }
293                 
294         /* build linked-list for searching */
295         BLI_dlrbTree_linkedlist_sync(&keys);
296         
297         /* start drawing keyframes 
298          *      - we use the binary-search capabilities of the tree to only start from 
299          *        the first visible keyframe (last one can then be easily checked)
300          *      - draw within a single GL block to be faster
301          */
302         glBegin(GL_LINES);
303                 for ( ak=time_cfra_find_ak(keys.root, v2d->cur.xmin); 
304                          (ak) && (ak->cfra <= v2d->cur.xmax); 
305                           ak=ak->next ) 
306                 {
307                         glVertex2f(ak->cfra, v2d->cur.ymin);
308                         glVertex2f(ak->cfra, v2d->cur.ymax);
309                 }
310         glEnd(); // GL_LINES
311                 
312         /* free temp stuff */
313         BLI_dlrbTree_free(&keys);
314 }
315
316 /* draw keyframe lines for timeline */
317 static void time_draw_keyframes(const bContext *C, SpaceTime *stime, ARegion *ar)
318 {
319         Scene *scene= CTX_data_scene(C);
320         Object *ob= CTX_data_active_object(C);
321         View2D *v2d= &ar->v2d;
322         short onlysel= (stime->flag & TIME_ONLYACTSEL);
323         
324         /* draw scene keyframes first 
325          *      - don't try to do this when only drawing active/selected data keyframes,
326          *        since this can become quite slow
327          */
328         if (scene && onlysel==0) {
329                 /* set draw color */
330                 glColor3ub(0xDD, 0xA7, 0x00);
331                 time_draw_idblock_keyframes(v2d, (ID *)scene, onlysel);
332         }
333         
334         /* draw keyframes from selected objects 
335          *      - only do the active object if in posemode (i.e. showing only keyframes for the bones)
336          *        OR the onlysel flag was set, which means that only active object's keyframes should
337          *        be considered
338          */
339         glColor3ub(0xDD, 0xD7, 0x00);
340         
341         if (ob && ((ob->mode == OB_MODE_POSE) || onlysel)) {
342                 /* draw keyframes for active object only */
343                 time_draw_idblock_keyframes(v2d, (ID *)ob, onlysel);
344         }
345         else {
346                 short active_done = 0;
347                 
348                 /* draw keyframes from all selected objects */
349                 CTX_DATA_BEGIN(C, Object*, obsel, selected_objects) 
350                 {
351                         /* last arg is 0, since onlysel doesn't apply here... */
352                         time_draw_idblock_keyframes(v2d, (ID *)obsel, 0);
353                         
354                         /* if this object is the active one, set flag so that we don't draw again */
355                         if (obsel == ob)
356                                 active_done= 1;
357                 }
358                 CTX_DATA_END;
359                 
360                 /* if active object hasn't been done yet, draw it... */
361                 if (ob && (active_done == 0))
362                         time_draw_idblock_keyframes(v2d, (ID *)ob, 0);
363         }
364 }
365
366 /* ---------------- */
367
368 static void time_refresh(const bContext *UNUSED(C), ScrArea *sa)
369 {
370         /* find the main timeline region and refresh cache display*/
371         ARegion *ar= BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
372         if(ar) {
373                 SpaceTime *stime = (SpaceTime *)sa->spacedata.first;
374                 time_cache_refresh(stime);
375         }
376 }
377
378 /* editor level listener */
379 static void time_listener(ScrArea *sa, wmNotifier *wmn)
380 {
381
382         /* mainly for updating cache display */
383         switch (wmn->category) {
384                 case NC_OBJECT:
385                         switch (wmn->data) {
386                                 case ND_BONE_ACTIVE:
387                                 case ND_POINTCACHE:
388                                 case ND_MODIFIER:
389                                 case ND_PARTICLE:
390                                         ED_area_tag_refresh(sa);
391                                         ED_area_tag_redraw(sa);
392                                         break;
393                         }
394                         break;
395                 case NC_SCENE:
396                         switch (wmn->data) {
397                                 case ND_OB_ACTIVE:
398                                 case ND_FRAME:
399                                         ED_area_tag_refresh(sa);
400                                         break;
401                                 case ND_FRAME_RANGE:
402                                         {
403                                                 ARegion *ar;
404                                                 Scene *scene = wmn->reference;
405
406                                                 for (ar= sa->regionbase.first; ar; ar= ar->next) {
407                                                         if (ar->regiontype==RGN_TYPE_WINDOW) {
408                                                                 ar->v2d.tot.xmin= (float)(SFRA - 4);
409                                                                 ar->v2d.tot.xmax= (float)(EFRA + 4);
410                                                                 break;
411                                                         }
412                                                 }
413                                         }
414                                         break;
415                         }
416                 case NC_SPACE:
417                         switch (wmn->data) {
418                                 case ND_SPACE_CHANGED:
419                                         ED_area_tag_refresh(sa);
420                                         break;
421                         }
422                 case NC_WM:
423                         switch (wmn->data) {
424                                 case ND_FILEREAD:
425                                         ED_area_tag_refresh(sa);
426                                         break;
427                         }
428         }
429 }
430
431 /* ---------------- */
432
433 /* add handlers, stuff you only do once or on area/region changes */
434 static void time_main_area_init(wmWindowManager *wm, ARegion *ar)
435 {
436         wmKeyMap *keymap;
437         
438         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
439         
440         /* own keymap */
441         keymap= WM_keymap_find(wm->defaultconf, "Timeline", SPACE_TIME, 0);
442         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
443 }
444
445 static void time_main_area_draw(const bContext *C, ARegion *ar)
446 {
447         /* draw entirely, view changes should be handled here */
448         Scene *scene= CTX_data_scene(C);
449         SpaceTime *stime= CTX_wm_space_time(C);
450         Object *obact = CTX_data_active_object(C);
451         View2D *v2d= &ar->v2d;
452         View2DGrid *grid;
453         View2DScrollers *scrollers;
454         int unit, flag=0;
455         
456         /* clear and setup matrix */
457         UI_ThemeClearColor(TH_BACK);
458         glClear(GL_COLOR_BUFFER_BIT);
459         
460         UI_view2d_view_ortho(v2d);
461
462         /* start and end frame */
463         time_draw_sfra_efra(scene, v2d);
464         
465         /* grid */
466         unit= (stime->flag & TIME_DRAWFRAMES)? V2D_UNIT_FRAMES: V2D_UNIT_SECONDS;
467         grid= UI_view2d_grid_calc(scene, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY, ar->winx, ar->winy);
468         UI_view2d_grid_draw(v2d, grid, (V2D_VERTICAL_LINES|V2D_VERTICAL_AXIS));
469         UI_view2d_grid_free(grid);
470         
471         /* current frame */
472         if ((stime->flag & TIME_DRAWFRAMES)==0)         flag |= DRAWCFRA_UNIT_SECONDS;
473         if (stime->flag & TIME_CFRA_NUM)                        flag |= DRAWCFRA_SHOW_NUMBOX;
474         ANIM_draw_cfra(C, v2d, flag);
475         
476         /* keyframes */
477         if(!G.rendering) /* ANIM_nla_mapping_apply_fcurve() modifies curve data while rendering, possible race condition */
478                 time_draw_keyframes(C, stime, ar);
479         
480         /* markers */
481         UI_view2d_view_orthoSpecial(ar, v2d, 1);
482         draw_markers_time(C, 0);
483         
484         /* caches */
485         time_draw_cache(stime, obact);
486         
487         /* reset view matrix */
488         UI_view2d_view_restore(C);
489         
490         /* scrollers */
491         scrollers= UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
492         UI_view2d_scrollers_draw(C, v2d, scrollers);
493         UI_view2d_scrollers_free(scrollers);
494 }
495
496 static void time_main_area_listener(ARegion *ar, wmNotifier *wmn)
497 {
498         /* context changes */
499         switch(wmn->category) {
500                 case NC_SPACE:
501                         if(wmn->data == ND_SPACE_TIME)
502                                 ED_region_tag_redraw(ar);
503                         break;
504
505                 case NC_ANIMATION:
506                         ED_region_tag_redraw(ar);
507                         break;
508                 
509                 case NC_SCENE:
510                         switch (wmn->data) {
511                                 case ND_OB_SELECT:
512                                 case ND_OB_ACTIVE:
513                                 case ND_FRAME:
514                                 case ND_FRAME_RANGE:
515                                 case ND_KEYINGSET:
516                                 case ND_RENDER_OPTIONS:
517                                         ED_region_tag_redraw(ar);
518                                 break;
519                         }
520         }
521 }
522
523 /* ************************ header time area region *********************** */
524
525 /* add handlers, stuff you only do once or on area/region changes */
526 static void time_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar)
527 {
528         ED_region_header_init(ar);
529 }
530
531 static void time_header_area_draw(const bContext *C, ARegion *ar)
532 {
533         ED_region_header(C, ar);
534 }
535
536 static void time_header_area_listener(ARegion *ar, wmNotifier *wmn)
537 {
538         /* context changes */
539         switch(wmn->category) {
540                 case NC_SCREEN:
541                         if(wmn->data==ND_ANIMPLAY)
542                                 ED_region_tag_redraw(ar);
543                         break;
544
545                 case NC_SCENE:
546                         switch (wmn->data) {
547                                 case ND_OB_SELECT:
548                                 case ND_FRAME:
549                                 case ND_FRAME_RANGE:
550                                 case ND_KEYINGSET:
551                                 case ND_RENDER_OPTIONS:
552                                         ED_region_tag_redraw(ar);
553                                 break;
554                         }
555
556                 case NC_SPACE:
557                         if(wmn->data == ND_SPACE_TIME)
558                                 ED_region_tag_redraw(ar);
559                         break;
560         }
561 }
562
563 /* ******************** default callbacks for time space ***************** */
564
565 static SpaceLink *time_new(const bContext *C)
566 {
567         Scene *scene= CTX_data_scene(C);
568         ARegion *ar;
569         SpaceTime *stime;
570
571         stime= MEM_callocN(sizeof(SpaceTime), "inittime");
572
573         stime->spacetype= SPACE_TIME;
574         stime->redraws= TIME_ALL_3D_WIN|TIME_ALL_ANIM_WIN; // XXX: depreceated
575         stime->flag |= TIME_DRAWFRAMES;
576
577         /* header */
578         ar= MEM_callocN(sizeof(ARegion), "header for time");
579         
580         BLI_addtail(&stime->regionbase, ar);
581         ar->regiontype= RGN_TYPE_HEADER;
582         ar->alignment= RGN_ALIGN_BOTTOM;
583         
584         /* main area */
585         ar= MEM_callocN(sizeof(ARegion), "main area for time");
586         
587         BLI_addtail(&stime->regionbase, ar);
588         ar->regiontype= RGN_TYPE_WINDOW;
589         
590         ar->v2d.tot.xmin= (float)(SFRA - 4);
591         ar->v2d.tot.ymin= 0.0f;
592         ar->v2d.tot.xmax= (float)(EFRA + 4);
593         ar->v2d.tot.ymax= 50.0f;
594         
595         ar->v2d.cur= ar->v2d.tot;
596
597         ar->v2d.min[0]= 1.0f;
598         ar->v2d.min[1]= 50.0f;
599
600         ar->v2d.max[0]= MAXFRAMEF;
601         ar->v2d.max[1]= 50.0; 
602
603         ar->v2d.minzoom= 0.1f;
604         ar->v2d.maxzoom= 10.0;
605
606         ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
607         ar->v2d.align |= V2D_ALIGN_NO_NEG_Y;
608         ar->v2d.keepofs |= V2D_LOCKOFS_Y;
609         ar->v2d.keepzoom |= V2D_LOCKZOOM_Y;
610
611
612         return (SpaceLink*)stime;
613 }
614
615 /* not spacelink itself */
616 static void time_free(SpaceLink *sl)
617 {
618         SpaceTime *stime= (SpaceTime *)sl;
619         
620         time_cache_free(stime);
621 }
622 /* spacetype; init callback in ED_area_initialize() */
623 /* init is called to (re)initialize an existing editor (file read, screen changes) */
624 /* validate spacedata, add own area level handlers */
625 static void time_init(wmWindowManager *UNUSED(wm), ScrArea *sa)
626 {
627         SpaceTime *stime= (SpaceTime *)sa->spacedata.first;
628         
629         time_cache_free(stime);
630         
631         /* enable all cache display */
632         stime->cache_display |= TIME_CACHE_DISPLAY;
633         stime->cache_display |= (TIME_CACHE_SOFTBODY|TIME_CACHE_PARTICLES);
634         stime->cache_display |= (TIME_CACHE_CLOTH|TIME_CACHE_SMOKE);
635 }
636
637 static SpaceLink *time_duplicate(SpaceLink *sl)
638 {
639         SpaceTime *stime= (SpaceTime *)sl;
640         SpaceTime *stimen= MEM_dupallocN(stime);
641         
642         stimen->caches.first = stimen->caches.last = NULL;
643         
644         return (SpaceLink *)stimen;
645 }
646
647 /* only called once, from space_api/spacetypes.c */
648 /* it defines all callbacks to maintain spaces */
649 void ED_spacetype_time(void)
650 {
651         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype time");
652         ARegionType *art;
653         
654         st->spaceid= SPACE_TIME;
655         strncpy(st->name, "Timeline", BKE_ST_MAXNAME);
656         
657         st->new= time_new;
658         st->free= time_free;
659         st->init= time_init;
660         st->duplicate= time_duplicate;
661         st->operatortypes= time_operatortypes;
662         st->keymap= NULL;
663         st->listener= time_listener;
664         st->refresh= time_refresh;
665         
666         /* regions: main window */
667         art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
668         art->regionid = RGN_TYPE_WINDOW;
669         art->keymapflag= ED_KEYMAP_VIEW2D|ED_KEYMAP_MARKERS|ED_KEYMAP_ANIMATION|ED_KEYMAP_FRAMES;
670         
671         art->init= time_main_area_init;
672         art->draw= time_main_area_draw;
673         art->listener= time_main_area_listener;
674         art->keymap= time_keymap;
675         BLI_addhead(&st->regiontypes, art);
676         
677         /* regions: header */
678         art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
679         art->regionid = RGN_TYPE_HEADER;
680         art->prefsizey= HEADERY;
681         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES|ED_KEYMAP_HEADER;
682         
683         art->init= time_header_area_init;
684         art->draw= time_header_area_draw;
685         art->listener= time_header_area_listener;
686         BLI_addhead(&st->regiontypes, art);
687                 
688         BKE_spacetype_register(st);
689 }
690