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