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