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