88c57d45b7955999182ad526f06b33ea5ca4fbfd
[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_screen.h"
46 #include "BKE_pointcache.h"
47
48 #include "ED_anim_api.h"
49 #include "ED_keyframes_draw.h"
50 #include "ED_screen.h"
51
52 #include "WM_api.h"
53 #include "WM_types.h"
54
55 #include "BIF_gl.h"
56 #include "BIF_glutil.h"
57
58 #include "UI_resources.h"
59 #include "UI_view2d.h"
60
61 #include "ED_space_api.h"
62 #include "ED_markers.h"
63
64 #include "time_intern.h"
65
66 /* ************************ main time area region *********************** */
67
68 static void time_draw_sfra_efra(Scene *scene, View2D *v2d)
69 {       
70         /* draw darkened area outside of active timeline 
71          * frame range used is preview range or scene range 
72          */
73         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
74         glEnable(GL_BLEND);
75         glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
76                 
77         if (PSFRA < PEFRA) {
78                 glRectf(v2d->cur.xmin, v2d->cur.ymin, (float)PSFRA, v2d->cur.ymax);
79                 glRectf((float)PEFRA, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
80         }
81         else {
82                 glRectf(v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
83         }
84         glDisable(GL_BLEND);
85
86         UI_ThemeColorShade(TH_BACK, -60);
87         /* thin lines where the actual frames are */
88         fdrawline((float)PSFRA, v2d->cur.ymin, (float)PSFRA, v2d->cur.ymax);
89         fdrawline((float)PEFRA, v2d->cur.ymin, (float)PEFRA, v2d->cur.ymax);
90 }
91
92 #define CACHE_DRAW_HEIGHT   3.0f
93
94 static void time_draw_cache(SpaceTime *stime, Object *ob, Scene *scene)
95 {
96         PTCacheID *pid;
97         ListBase pidlist;
98         SpaceTimeCache *stc = stime->caches.first;
99         float yoffs = 0.f;
100         
101         if (!(stime->cache_display & TIME_CACHE_DISPLAY) || (!ob))
102                 return;
103
104         BKE_ptcache_ids_from_object(&pidlist, ob, scene, 0);
105
106         /* iterate over pointcaches on the active object, 
107          * add spacetimecache and vertex array for each */
108         for (pid = pidlist.first; pid; pid = pid->next) {
109                 float col[4], *fp;
110                 int i, sta = pid->cache->startframe, end = pid->cache->endframe;
111                 int len = (end - sta + 1) * 4;
112
113                 switch (pid->type) {
114                         case PTCACHE_TYPE_SOFTBODY:
115                                 if (!(stime->cache_display & TIME_CACHE_SOFTBODY)) continue;
116                                 break;
117                         case PTCACHE_TYPE_PARTICLES:
118                                 if (!(stime->cache_display & TIME_CACHE_PARTICLES)) continue;
119                                 break;
120                         case PTCACHE_TYPE_CLOTH:
121                                 if (!(stime->cache_display & TIME_CACHE_CLOTH)) continue;
122                                 break;
123                         case PTCACHE_TYPE_SMOKE_DOMAIN:
124                         case PTCACHE_TYPE_SMOKE_HIGHRES:
125                                 if (!(stime->cache_display & TIME_CACHE_SMOKE)) continue;
126                                 break;
127                         case PTCACHE_TYPE_DYNAMICPAINT:
128                                 if (!(stime->cache_display & TIME_CACHE_DYNAMICPAINT)) continue;
129                                 break;
130                         case PTCACHE_TYPE_RIGIDBODY:
131                                 if (!(stime->cache_display & TIME_CACHE_RIGIDBODY)) continue;
132                                 break;
133                 }
134
135                 if (pid->cache->cached_frames == NULL)
136                         continue;
137
138                 /* make sure we have stc with correct array length */
139                 if (stc == NULL || MEM_allocN_len(stc->array) != len * 2 * sizeof(float)) {
140                         if (stc) {
141                                 MEM_freeN(stc->array);
142                         }
143                         else {
144                                 stc = MEM_callocN(sizeof(SpaceTimeCache), "spacetimecache");
145                                 BLI_addtail(&stime->caches, stc);
146                         }
147
148                         stc->array = MEM_callocN(len * 2 * sizeof(float), "SpaceTimeCache array");
149                 }
150
151                 /* fill the vertex array with a quad for each cached frame */
152                 for (i = sta, fp = stc->array; i <= end; i++) {
153                         if (pid->cache->cached_frames[i - sta]) {
154                                 fp[0] = (float)i - 0.5f;
155                                 fp[1] = 0.0;
156                                 fp += 2;
157                                 
158                                 fp[0] = (float)i - 0.5f;
159                                 fp[1] = 1.0;
160                                 fp += 2;
161                                 
162                                 fp[0] = (float)i + 0.5f;
163                                 fp[1] = 1.0;
164                                 fp += 2;
165                                 
166                                 fp[0] = (float)i + 0.5f;
167                                 fp[1] = 0.0;
168                                 fp += 2;
169                         }
170                 }
171                 
172                 glPushMatrix();
173                 glTranslatef(0.0, (float)V2D_SCROLL_HEIGHT + yoffs, 0.0);
174                 glScalef(1.0, CACHE_DRAW_HEIGHT, 0.0);
175                 
176                 switch (pid->type) {
177                         case PTCACHE_TYPE_SOFTBODY:
178                                 col[0] = 1.0;   col[1] = 0.4;   col[2] = 0.02;
179                                 col[3] = 0.1;
180                                 break;
181                         case PTCACHE_TYPE_PARTICLES:
182                                 col[0] = 1.0;   col[1] = 0.1;   col[2] = 0.02;
183                                 col[3] = 0.1;
184                                 break;
185                         case PTCACHE_TYPE_CLOTH:
186                                 col[0] = 0.1;   col[1] = 0.1;   col[2] = 0.75;
187                                 col[3] = 0.1;
188                                 break;
189                         case PTCACHE_TYPE_SMOKE_DOMAIN:
190                         case PTCACHE_TYPE_SMOKE_HIGHRES:
191                                 col[0] = 0.2;   col[1] = 0.2;   col[2] = 0.2;
192                                 col[3] = 0.1;
193                                 break;
194                         case PTCACHE_TYPE_DYNAMICPAINT:
195                                 col[0] = 1.0;   col[1] = 0.1;   col[2] = 0.75;
196                                 col[3] = 0.1;
197                                 break;
198                         case PTCACHE_TYPE_RIGIDBODY:
199                                 col[0] = 1.0;   col[1] = 0.6;   col[2] = 0.0;
200                                 col[3] = 0.1;
201                                 break;
202                         default:
203                                 col[0] = 1.0;   col[1] = 0.0;   col[2] = 1.0;
204                                 col[3] = 0.1;
205                                 BLI_assert(0);
206                                 break;
207                 }
208                 glColor4fv(col);
209                 
210                 glEnable(GL_BLEND);
211                 
212                 glRectf((float)sta, 0.0, (float)end, 1.0);
213                 
214                 col[3] = 0.4f;
215                 if (pid->cache->flag & PTCACHE_BAKED) {
216                         col[0] -= 0.4f; col[1] -= 0.4f; col[2] -= 0.4f;
217                 }
218                 else if (pid->cache->flag & PTCACHE_OUTDATED) {
219                         col[0] += 0.4f; col[1] += 0.4f; col[2] += 0.4f;
220                 }
221                 glColor4fv(col);
222                 
223                 glEnableClientState(GL_VERTEX_ARRAY);
224                 glVertexPointer(2, GL_FLOAT, 0, stc->array);
225                 glDrawArrays(GL_QUADS, 0, (fp - stc->array) / 2);
226                 glDisableClientState(GL_VERTEX_ARRAY);
227                 
228                 glDisable(GL_BLEND);
229                 
230                 glPopMatrix();
231                 
232                 yoffs += CACHE_DRAW_HEIGHT;
233
234                 stc = stc->next;
235         }
236
237         BLI_freelistN(&pidlist);
238
239         /* free excessive caches */
240         while (stc) {
241                 SpaceTimeCache *tmp = stc->next;
242                 BLI_remlink(&stime->caches, stc);
243                 MEM_freeN(stc->array);
244                 MEM_freeN(stc);
245                 stc = tmp;
246         }
247 }
248
249 static void time_cache_free(SpaceTime *stime)
250 {
251         SpaceTimeCache *stc;
252         
253         for (stc = stime->caches.first; stc; stc = stc->next) {
254                 if (stc->array) {
255                         MEM_freeN(stc->array);
256                         stc->array = NULL;
257                 }
258         }
259         
260         BLI_freelistN(&stime->caches);
261 }
262
263 static void time_cache_refresh(SpaceTime *stime)
264 {
265         /* Free previous caches to indicate full refresh */
266         time_cache_free(stime);
267 }
268
269 /* helper function - find actkeycolumn that occurs on cframe, or the nearest one if not found */
270 static ActKeyColumn *time_cfra_find_ak(ActKeyColumn *ak, float cframe)
271 {
272         ActKeyColumn *akn = NULL;
273         
274         /* sanity checks */
275         if (ak == NULL)
276                 return NULL;
277         
278         /* check if this is a match, or whether it is in some subtree */
279         if (cframe < ak->cfra)
280                 akn = time_cfra_find_ak(ak->left, cframe);
281         else if (cframe > ak->cfra)
282                 akn = time_cfra_find_ak(ak->right, cframe);
283                 
284         /* if no match found (or found match), just use the current one */
285         if (akn == NULL)
286                 return ak;
287         else
288                 return akn;
289 }
290
291 /* helper for time_draw_keyframes() */
292 static void time_draw_idblock_keyframes(View2D *v2d, ID *id, short onlysel)
293 {
294         bDopeSheet ads = {NULL};
295         DLRBT_Tree keys;
296         ActKeyColumn *ak;
297         
298         /* init binarytree-list for getting keyframes */
299         BLI_dlrbTree_init(&keys);
300         
301         /* init dopesheet settings */
302         if (onlysel)
303                 ads.filterflag |= ADS_FILTER_ONLYSEL;
304         
305         /* populate tree with keyframe nodes */
306         switch (GS(id->name)) {
307                 case ID_SCE:
308                         scene_to_keylist(&ads, (Scene *)id, &keys, NULL);
309                         break;
310                 case ID_OB:
311                         ob_to_keylist(&ads, (Object *)id, &keys, NULL);
312                         break;
313         }
314                 
315         /* build linked-list for searching */
316         BLI_dlrbTree_linkedlist_sync(&keys);
317         
318         /* start drawing keyframes 
319          *      - we use the binary-search capabilities of the tree to only start from 
320          *        the first visible keyframe (last one can then be easily checked)
321          *      - draw within a single GL block to be faster
322          */
323         glBegin(GL_LINES);
324         for (ak = time_cfra_find_ak(keys.root, v2d->cur.xmin);
325              (ak) && (ak->cfra <= v2d->cur.xmax);
326              ak = ak->next)
327         {
328                 glVertex2f(ak->cfra, v2d->tot.ymin);
329                 glVertex2f(ak->cfra, v2d->tot.ymax);
330         }
331         glEnd(); // GL_LINES
332                 
333         /* free temp stuff */
334         BLI_dlrbTree_free(&keys);
335 }
336
337 /* draw keyframe lines for timeline */
338 static void time_draw_keyframes(const bContext *C, ARegion *ar)
339 {
340         Scene *scene = CTX_data_scene(C);
341         Object *ob = CTX_data_active_object(C);
342         View2D *v2d = &ar->v2d;
343         bool onlysel = ((scene->flag & SCE_KEYS_NO_SELONLY) == 0);
344         
345         /* draw scene keyframes first 
346          *      - don't try to do this when only drawing active/selected data keyframes,
347          *        since this can become quite slow
348          */
349         if (onlysel == 0) {
350                 /* set draw color */
351                 glColor3ub(0xDD, 0xA7, 0x00);
352                 time_draw_idblock_keyframes(v2d, (ID *)scene, onlysel);
353         }
354         
355         /* draw keyframes from selected objects 
356          *  - only do the active object if in posemode (i.e. showing only keyframes for the bones)
357          *    OR the onlysel flag was set, which means that only active object's keyframes should
358          *    be considered
359          */
360         glColor3ub(0xDD, 0xD7, 0x00);
361         
362         if (ob && ((ob->mode == OB_MODE_POSE) || onlysel)) {
363                 /* draw keyframes for active object only */
364                 time_draw_idblock_keyframes(v2d, (ID *)ob, onlysel);
365         }
366         else {
367                 bool active_done = false;
368                 
369                 /* draw keyframes from all selected objects */
370                 CTX_DATA_BEGIN (C, Object *, obsel, selected_objects)
371                 {
372                         /* last arg is 0, since onlysel doesn't apply here... */
373                         time_draw_idblock_keyframes(v2d, (ID *)obsel, 0);
374                         
375                         /* if this object is the active one, set flag so that we don't draw again */
376                         if (obsel == ob)
377                                 active_done = true;
378                 }
379                 CTX_DATA_END;
380                 
381                 /* if active object hasn't been done yet, draw it... */
382                 if (ob && (active_done == 0))
383                         time_draw_idblock_keyframes(v2d, (ID *)ob, 0);
384         }
385 }
386
387 /* ---------------- */
388
389 static void time_refresh(const bContext *UNUSED(C), ScrArea *sa)
390 {
391         /* find the main timeline region and refresh cache display*/
392         ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
393         if (ar) {
394                 SpaceTime *stime = (SpaceTime *)sa->spacedata.first;
395                 time_cache_refresh(stime);
396         }
397 }
398
399 /* editor level listener */
400 static void time_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn)
401 {
402
403         /* mainly for updating cache display */
404         switch (wmn->category) {
405                 case NC_OBJECT:
406                 {
407                         switch (wmn->data) {
408                                 case ND_BONE_SELECT:
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 }