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