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