Fix #35390: sequencer end frame of preview range was not drawing correct.
[blender.git] / source / blender / editors / space_graph / space_graph.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_graph/space_graph.c
28  *  \ingroup spgraph
29  */
30
31
32 #include <string.h>
33 #include <stdio.h>
34
35 #include "DNA_anim_types.h"
36 #include "DNA_scene_types.h"
37
38 #include "MEM_guardedalloc.h"
39
40 #include "BLI_blenlib.h"
41 #include "BLI_math.h"
42 #include "BLI_utildefines.h"
43
44 #include "BKE_context.h"
45 #include "BKE_global.h"
46 #include "BKE_main.h"
47 #include "BKE_fcurve.h"
48 #include "BKE_screen.h"
49
50 #include "ED_space_api.h"
51 #include "ED_screen.h"
52 #include "ED_anim_api.h"
53 #include "ED_markers.h"
54
55 #include "BIF_gl.h"
56
57 #include "WM_api.h"
58 #include "WM_types.h"
59
60 #include "UI_resources.h"
61 #include "UI_view2d.h"
62
63 #include "graph_intern.h"   // own include
64
65 /* ******************** manage regions ********************* */
66
67 ARegion *graph_has_buttons_region(ScrArea *sa)
68 {
69         ARegion *ar, *arnew;
70         
71         ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
72         if (ar) return ar;
73
74         /* add subdiv level; after main */
75         ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
76
77         /* is error! */
78         if (ar == NULL) return NULL;
79         
80         arnew = MEM_callocN(sizeof(ARegion), "buttons for graph");
81         
82         BLI_insertlinkafter(&sa->regionbase, ar, arnew);
83         arnew->regiontype = RGN_TYPE_UI;
84         arnew->alignment = RGN_ALIGN_RIGHT;
85         
86         arnew->flag = RGN_FLAG_HIDDEN;
87         
88         return arnew;
89 }
90
91
92 /* ******************** default callbacks for ipo space ***************** */
93
94 static SpaceLink *graph_new(const bContext *C)
95 {
96         Scene *scene = CTX_data_scene(C);
97         ARegion *ar;
98         SpaceIpo *sipo;
99         
100         /* Graph Editor - general stuff */
101         sipo = MEM_callocN(sizeof(SpaceIpo), "init graphedit");
102         sipo->spacetype = SPACE_IPO;
103         
104         sipo->autosnap = SACTSNAP_FRAME;
105         
106         /* allocate DopeSheet data for Graph Editor */
107         sipo->ads = MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet");
108         sipo->ads->source = (ID *)scene;
109         
110         /* settings for making it easier by default to just see what you're interested in tweaking */
111         sipo->ads->filterflag |= ADS_FILTER_ONLYSEL;
112         sipo->flag |= SIPO_SELVHANDLESONLY;
113         
114         /* header */
115         ar = MEM_callocN(sizeof(ARegion), "header for graphedit");
116         
117         BLI_addtail(&sipo->regionbase, ar);
118         ar->regiontype = RGN_TYPE_HEADER;
119         ar->alignment = RGN_ALIGN_BOTTOM;
120         
121         /* channels */
122         ar = MEM_callocN(sizeof(ARegion), "channels area for graphedit");
123         
124         BLI_addtail(&sipo->regionbase, ar);
125         ar->regiontype = RGN_TYPE_CHANNELS;
126         ar->alignment = RGN_ALIGN_LEFT;
127         
128         ar->v2d.scroll = (V2D_SCROLL_RIGHT | V2D_SCROLL_BOTTOM);
129         
130         /* ui buttons */
131         ar = MEM_callocN(sizeof(ARegion), "buttons area for graphedit");
132         
133         BLI_addtail(&sipo->regionbase, ar);
134         ar->regiontype = RGN_TYPE_UI;
135         ar->alignment = RGN_ALIGN_RIGHT;
136         ar->flag = RGN_FLAG_HIDDEN;
137         
138         /* main area */
139         ar = MEM_callocN(sizeof(ARegion), "main area for graphedit");
140         
141         BLI_addtail(&sipo->regionbase, ar);
142         ar->regiontype = RGN_TYPE_WINDOW;
143         
144         ar->v2d.tot.xmin = 0.0f;
145         ar->v2d.tot.ymin = (float)scene->r.sfra - 10.0f;
146         ar->v2d.tot.xmax = (float)scene->r.efra;
147         ar->v2d.tot.ymax = 10.0f;
148         
149         ar->v2d.cur = ar->v2d.tot;
150         
151         ar->v2d.min[0] = FLT_MIN;
152         ar->v2d.min[1] = FLT_MIN;
153
154         ar->v2d.max[0] = MAXFRAMEF;
155         ar->v2d.max[1] = FLT_MAX;
156         
157         ar->v2d.scroll = (V2D_SCROLL_BOTTOM | V2D_SCROLL_SCALE_HORIZONTAL);
158         ar->v2d.scroll |= (V2D_SCROLL_LEFT | V2D_SCROLL_SCALE_VERTICAL);
159         
160         ar->v2d.keeptot = 0;
161         
162         return (SpaceLink *)sipo;
163 }
164
165 /* not spacelink itself */
166 static void graph_free(SpaceLink *sl)
167 {       
168         SpaceIpo *si = (SpaceIpo *)sl;
169         
170         if (si->ads) {
171                 BLI_freelistN(&si->ads->chanbase);
172                 MEM_freeN(si->ads);
173         }
174         
175         if (si->ghostCurves.first)
176                 free_fcurves(&si->ghostCurves);
177 }
178
179
180 /* spacetype; init callback */
181 static void graph_init(struct wmWindowManager *UNUSED(wm), ScrArea *sa)
182 {
183         SpaceIpo *sipo = (SpaceIpo *)sa->spacedata.first;
184         
185         /* init dopesheet data if non-existant (i.e. for old files) */
186         if (sipo->ads == NULL) {
187                 sipo->ads = MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet");
188                 sipo->ads->source = (ID *)(G.main->scene.first); // FIXME: this is a really nasty hack here for now...
189         }
190         
191         /* force immediate init of any invalid F-Curve colors */
192         sipo->flag |= SIPO_TEMP_NEEDCHANSYNC;
193         ED_area_tag_refresh(sa);
194 }
195
196 static SpaceLink *graph_duplicate(SpaceLink *sl)
197 {
198         SpaceIpo *sipon = MEM_dupallocN(sl);
199         
200         /* clear or remove stuff from old */
201         BLI_duplicatelist(&sipon->ghostCurves, &((SpaceIpo *)sl)->ghostCurves);
202         sipon->ads = MEM_dupallocN(sipon->ads);
203         
204         return (SpaceLink *)sipon;
205 }
206
207 /* add handlers, stuff you only do once or on area/region changes */
208 static void graph_main_area_init(wmWindowManager *wm, ARegion *ar)
209 {
210         wmKeyMap *keymap;
211         
212         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
213         
214         /* own keymap */
215         keymap = WM_keymap_find(wm->defaultconf, "Graph Editor", SPACE_IPO, 0);
216         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
217         keymap = WM_keymap_find(wm->defaultconf, "Graph Editor Generic", SPACE_IPO, 0);
218         WM_event_add_keymap_handler(&ar->handlers, keymap);
219 }
220
221 static void graph_main_area_draw(const bContext *C, ARegion *ar)
222 {
223         /* draw entirely, view changes should be handled here */
224         SpaceIpo *sipo = CTX_wm_space_graph(C);
225         bAnimContext ac;
226         View2D *v2d = &ar->v2d;
227         View2DGrid *grid;
228         View2DScrollers *scrollers;
229         float col[3];
230         short unitx = 0, unity = V2D_UNIT_VALUES, flag = 0;
231         
232         /* clear and setup matrix */
233         UI_GetThemeColor3fv(TH_BACK, col);
234         glClearColor(col[0], col[1], col[2], 0.0);
235         glClear(GL_COLOR_BUFFER_BIT);
236         
237         UI_view2d_view_ortho(v2d);
238         
239         /* grid */
240         unitx = (sipo->flag & SIPO_DRAWTIME) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMESCALE;
241         grid = UI_view2d_grid_calc(CTX_data_scene(C), v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP, ar->winx, ar->winy);
242         UI_view2d_grid_draw(v2d, grid, V2D_GRIDLINES_ALL);
243         
244         ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
245
246         /* draw data */
247         if (ANIM_animdata_get_context(C, &ac)) {
248                 /* draw ghost curves */
249                 graph_draw_ghost_curves(&ac, sipo, ar);
250                 
251                 /* draw curves twice - unselected, then selected, so that the are fewer occlusion problems */
252                 graph_draw_curves(&ac, sipo, ar, grid, 0);
253                 graph_draw_curves(&ac, sipo, ar, grid, 1);
254                 
255                 /* XXX the slow way to set tot rect... but for nice sliders needed (ton) */
256                 get_graph_keyframe_extents(&ac, &v2d->tot.xmin, &v2d->tot.xmax, &v2d->tot.ymin, &v2d->tot.ymax, FALSE, TRUE);
257                 /* extra offset so that these items are visible */
258                 v2d->tot.xmin -= 10.0f;
259                 v2d->tot.xmax += 10.0f;
260         }
261         
262         /* only free grid after drawing data, as we need to use it to determine sampling rate */
263         UI_view2d_grid_free(grid);
264         
265         /* horizontal component of value-cursor (value line before the current frame line) */
266         if ((sipo->flag & SIPO_NODRAWCURSOR) == 0) {
267                 float vec[2];
268                 
269                 /* Draw a green line to indicate the cursor value */
270                 vec[1] = sipo->cursorVal;
271                 
272                 UI_ThemeColorShadeAlpha(TH_CFRAME, -10, -50);
273                 glLineWidth(2.0);
274                 
275                 glEnable(GL_BLEND);
276                 glBegin(GL_LINE_STRIP);
277                 vec[0] = v2d->cur.xmin;
278                 glVertex2fv(vec);
279                         
280                 vec[0] = v2d->cur.xmax;
281                 glVertex2fv(vec);
282                 glEnd(); // GL_LINE_STRIP
283                 glDisable(GL_BLEND);
284         }
285         
286         /* current frame */
287         if (sipo->flag & SIPO_DRAWTIME) flag |= DRAWCFRA_UNIT_SECONDS;
288         if ((sipo->flag & SIPO_NODRAWCFRANUM) == 0) flag |= DRAWCFRA_SHOW_NUMBOX;
289         ANIM_draw_cfra(C, v2d, flag);
290         
291         /* markers */
292         UI_view2d_view_orthoSpecial(ar, v2d, 1);
293         draw_markers_time(C, 0);
294         
295         /* preview range */
296         UI_view2d_view_ortho(v2d);
297         ANIM_draw_previewrange(C, v2d, 0);
298         
299         /* callback */
300         UI_view2d_view_ortho(v2d);
301         ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
302
303         /* reset view matrix */
304         UI_view2d_view_restore(C);
305         
306         /* scrollers */
307         // FIXME: args for scrollers depend on the type of data being shown...
308         scrollers = UI_view2d_scrollers_calc(C, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP);
309         UI_view2d_scrollers_draw(C, v2d, scrollers);
310         UI_view2d_scrollers_free(scrollers);
311 }
312
313 static void graph_channel_area_init(wmWindowManager *wm, ARegion *ar)
314 {
315         wmKeyMap *keymap;
316         
317         /* make sure we keep the hide flags */
318         ar->v2d.scroll |= (V2D_SCROLL_RIGHT | V2D_SCROLL_BOTTOM);
319         ar->v2d.scroll &= ~(V2D_SCROLL_LEFT | V2D_SCROLL_TOP);  /* prevent any noise of past */
320         ar->v2d.scroll |= V2D_SCROLL_HORIZONTAL_HIDE;
321         ar->v2d.scroll |= V2D_SCROLL_VERTICAL_HIDE;
322         
323         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
324         
325         /* own keymap */
326         keymap = WM_keymap_find(wm->defaultconf, "Animation Channels", 0, 0);
327         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
328         keymap = WM_keymap_find(wm->defaultconf, "Graph Editor Generic", SPACE_IPO, 0);
329         WM_event_add_keymap_handler(&ar->handlers, keymap);
330 }
331
332 static void graph_channel_area_draw(const bContext *C, ARegion *ar)
333 {
334         bAnimContext ac;
335         View2D *v2d = &ar->v2d;
336         View2DScrollers *scrollers;
337         float col[3];
338         
339         /* clear and setup matrix */
340         UI_GetThemeColor3fv(TH_BACK, col);
341         glClearColor(col[0], col[1], col[2], 0.0);
342         glClear(GL_COLOR_BUFFER_BIT);
343         
344         UI_view2d_view_ortho(v2d);
345         
346         /* draw channels */
347         if (ANIM_animdata_get_context(C, &ac)) {
348                 graph_draw_channel_names((bContext *)C, &ac, ar);
349         }
350         
351         /* reset view matrix */
352         UI_view2d_view_restore(C);
353         
354         /* scrollers */
355         scrollers = UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
356         UI_view2d_scrollers_draw(C, v2d, scrollers);
357         UI_view2d_scrollers_free(scrollers);
358 }
359
360 /* add handlers, stuff you only do once or on area/region changes */
361 static void graph_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar)
362 {
363         ED_region_header_init(ar);
364 }
365
366 static void graph_header_area_draw(const bContext *C, ARegion *ar)
367 {
368         ED_region_header(C, ar);
369 }
370
371 /* add handlers, stuff you only do once or on area/region changes */
372 static void graph_buttons_area_init(wmWindowManager *wm, ARegion *ar)
373 {
374         wmKeyMap *keymap;
375         
376         ED_region_panels_init(wm, ar);
377
378         keymap = WM_keymap_find(wm->defaultconf, "Graph Editor Generic", SPACE_IPO, 0);
379         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
380 }
381
382 static void graph_buttons_area_draw(const bContext *C, ARegion *ar)
383 {
384         ED_region_panels(C, ar, 1, NULL, -1);
385 }
386
387 static void graph_region_listener(ARegion *ar, wmNotifier *wmn)
388 {
389         /* context changes */
390         switch (wmn->category) {
391                 case NC_ANIMATION:
392                         ED_region_tag_redraw(ar);
393                         break;
394                 case NC_SCENE:
395                         switch (wmn->data) {
396                                 case ND_RENDER_OPTIONS:
397                                 case ND_OB_ACTIVE:
398                                 case ND_FRAME:
399                                 case ND_MARKERS:
400                                         ED_region_tag_redraw(ar);
401                                         break;
402                                 case ND_SEQUENCER:
403                                         if (wmn->action == NA_SELECTED)
404                                                 ED_region_tag_redraw(ar);
405                                         break;
406                         }
407                         break;
408                 case NC_OBJECT:
409                         switch (wmn->data) {
410                                 case ND_BONE_ACTIVE:
411                                 case ND_BONE_SELECT:
412                                 case ND_KEYS:
413                                         ED_region_tag_redraw(ar);
414                                         break;
415                                 case ND_MODIFIER:
416                                         if (wmn->action == NA_RENAME)
417                                                 ED_region_tag_redraw(ar);
418                                         break;
419                         }
420                         break;
421                 case NC_NODE:
422                         switch (wmn->action) {
423                                 case NA_EDITED:
424                                 case NA_SELECTED:
425                                         ED_region_tag_redraw(ar);
426                                         break;
427                         }
428                         break;
429                 case NC_ID:
430                         if (wmn->action == NA_RENAME)
431                                 ED_region_tag_redraw(ar);
432                         break;
433                 default:
434                         if (wmn->data == ND_KEYS)
435                                 ED_region_tag_redraw(ar);
436                                 
437         }
438 }
439
440 /* editor level listener */
441 static void graph_listener(ScrArea *sa, wmNotifier *wmn)
442 {
443         SpaceIpo *sipo = (SpaceIpo *)sa->spacedata.first;
444         
445         /* context changes */
446         switch (wmn->category) {
447                 case NC_ANIMATION:
448                         /* for selection changes of animation data, we can just redraw... otherwise autocolor might need to be done again */
449                         if (ELEM(wmn->data, ND_KEYFRAME, ND_ANIMCHAN) && (wmn->action == NA_SELECTED))
450                                 ED_area_tag_redraw(sa);
451                         else
452                                 ED_area_tag_refresh(sa);
453                         break;
454                 case NC_SCENE:
455                         switch (wmn->data) {
456                                 case ND_OB_ACTIVE:  /* selection changed, so force refresh to flush (needs flag set to do syncing)  */
457                                 case ND_OB_SELECT:
458                                         sipo->flag |= SIPO_TEMP_NEEDCHANSYNC;
459                                         ED_area_tag_refresh(sa);
460                                         break;
461                                         
462                                 default: /* just redrawing the view will do */
463                                         ED_area_tag_redraw(sa);
464                                         break;
465                         }
466                         break;
467                 case NC_OBJECT:
468                         switch (wmn->data) {
469                                 case ND_BONE_SELECT:    /* selection changed, so force refresh to flush (needs flag set to do syncing) */
470                                 case ND_BONE_ACTIVE:
471                                         sipo->flag |= SIPO_TEMP_NEEDCHANSYNC;
472                                         ED_area_tag_refresh(sa);
473                                         break;
474                                 case ND_TRANSFORM:
475                                         break; /*do nothing*/
476                                         
477                                 default: /* just redrawing the view will do */
478                                         ED_area_tag_redraw(sa);
479                                         break;
480                         }
481                         break;
482                 case NC_NODE:
483                         if (wmn->action == NA_SELECTED) {
484                                 /* selection changed, so force refresh to flush (needs flag set to do syncing) */
485                                 sipo->flag |= SIPO_TEMP_NEEDCHANSYNC;
486                                 ED_area_tag_refresh(sa);
487                         }
488                         break;
489                 case NC_SPACE:
490                         if (wmn->data == ND_SPACE_GRAPH)
491                                 ED_area_tag_redraw(sa);
492                         break;
493                 case NC_WINDOW:
494                         if (sipo->flag & SIPO_TEMP_NEEDCHANSYNC) {
495                                 /* force redraw/refresh after undo/redo - prevents "black curve" problem */
496                                 ED_area_tag_refresh(sa);
497                         }
498                         break;
499                         
500                         // XXX: restore the case below if not enough updates occur...
501                         //default:
502                         //      if (wmn->data == ND_KEYS)
503                         //              ED_area_tag_redraw(sa);
504         }
505 }
506
507
508
509 static void graph_refresh(const bContext *C, ScrArea *sa)
510 {
511         SpaceIpo *sipo = (SpaceIpo *)sa->spacedata.first;
512         bAnimContext ac;
513         
514         /* updates to data needed depends on Graph Editor mode... */
515         switch (sipo->mode) {
516                 case SIPO_MODE_ANIMATION: /* all animation */
517                 {
518                         
519                 }
520                 break;
521                 
522                 case SIPO_MODE_DRIVERS: /* drivers only  */
523                 {
524                 
525                 }
526                 break;
527         }
528         
529         /* region updates? */
530         // XXX re-sizing y-extents of tot should go here?
531         
532         /* update the state of the animchannels in response to changes from the data they represent 
533          * NOTE: the temp flag is used to indicate when this needs to be done, and will be cleared once handled
534          */
535         if (sipo->flag & SIPO_TEMP_NEEDCHANSYNC) {
536                 ANIM_sync_animchannels_to_data(C);
537                 sipo->flag &= ~SIPO_TEMP_NEEDCHANSYNC;
538                 ED_area_tag_redraw(sa);
539         }
540         
541         /* init/adjust F-Curve colors */
542         if (ANIM_animdata_get_context(C, &ac)) {
543                 ListBase anim_data = {NULL, NULL};
544                 bAnimListElem *ale;
545                 size_t items;
546                 int filter;
547                 int i;
548                 
549                 /* build list of F-Curves which will be visible as channels in channel-region
550                  *  - we don't include ANIMFILTER_CURVEVISIBLE filter, as that will result in a
551                  *    mismatch between channel-colors and the drawn curves
552                  */
553                 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_NODUPLIS);
554                 items = ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
555                 
556                 /* loop over F-Curves, assigning colors */
557                 for (ale = anim_data.first, i = 0; ale; ale = ale->next, i++) {
558                         FCurve *fcu = (FCurve *)ale->data;
559                         
560                         /* set color of curve here */
561                         switch (fcu->color_mode) {
562                                 case FCURVE_COLOR_CUSTOM:
563                                         /* User has defined a custom color for this curve already (we assume it's not going to cause clashes with text colors),
564                                          * which should be left alone... Nothing needs to be done here.
565                                          */
566                                         break;
567                                         
568                                 case FCURVE_COLOR_AUTO_RGB:
569                                 {
570                                         /* F-Curve's array index is automatically mapped to RGB values. This works best of 3-value vectors. 
571                                          * TODO: find a way to module the hue so that not all curves have same color...
572                                          */
573                                         float *col = fcu->color;
574                                         
575                                         switch (fcu->array_index) {
576                                                 case 0:
577                                                         UI_GetThemeColor3fv(TH_AXIS_X, col);
578                                                         break;
579                                                 case 1:
580                                                         UI_GetThemeColor3fv(TH_AXIS_Y, col);
581                                                         break;
582                                                 case 2:
583                                                         UI_GetThemeColor3fv(TH_AXIS_Z, col);
584                                                         break;
585                                                 default:
586                                                         /* 'unknown' color - bluish so as to not conflict with handles */
587                                                         col[0] = 0.3f; col[1] = 0.8f; col[2] = 1.0f;
588                                                         break;
589                                         }
590                                 }
591                                 break;
592                                 
593                                 case FCURVE_COLOR_AUTO_RAINBOW:
594                                 default:
595                                 {
596                                         /* determine color 'automatically' using 'magic function' which uses the given args
597                                          * of current item index + total items to determine some RGB color
598                                          */
599                                         getcolor_fcurve_rainbow(i, items, fcu->color);
600                                 }
601                                 break;
602                         }
603                 }
604                 
605                 /* free temp list */
606                 BLI_freelistN(&anim_data);
607         }
608 }
609
610 /* only called once, from space/spacetypes.c */
611 void ED_spacetype_ipo(void)
612 {
613         SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype ipo");
614         ARegionType *art;
615         
616         st->spaceid = SPACE_IPO;
617         strncpy(st->name, "Graph", BKE_ST_MAXNAME);
618         
619         st->new = graph_new;
620         st->free = graph_free;
621         st->init = graph_init;
622         st->duplicate = graph_duplicate;
623         st->operatortypes = graphedit_operatortypes;
624         st->keymap = graphedit_keymap;
625         st->listener = graph_listener;
626         st->refresh = graph_refresh;
627         
628         /* regions: main window */
629         art = MEM_callocN(sizeof(ARegionType), "spacetype graphedit region");
630         art->regionid = RGN_TYPE_WINDOW;
631         art->init = graph_main_area_init;
632         art->draw = graph_main_area_draw;
633         art->listener = graph_region_listener;
634         art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_MARKERS | ED_KEYMAP_ANIMATION | ED_KEYMAP_FRAMES;
635
636         BLI_addhead(&st->regiontypes, art);
637         
638         /* regions: header */
639         art = MEM_callocN(sizeof(ARegionType), "spacetype graphedit region");
640         art->regionid = RGN_TYPE_HEADER;
641         art->prefsizey = HEADERY;
642         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER;
643         art->listener = graph_region_listener;
644         art->init = graph_header_area_init;
645         art->draw = graph_header_area_draw;
646         
647         BLI_addhead(&st->regiontypes, art);
648         
649         /* regions: channels */
650         art = MEM_callocN(sizeof(ARegionType), "spacetype graphedit region");
651         art->regionid = RGN_TYPE_CHANNELS;
652         art->prefsizex = 200 + V2D_SCROLL_WIDTH; /* 200 is the 'standard', but due to scrollers, we want a bit more to fit the lock icons in */
653         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES;
654         art->listener = graph_region_listener;
655         art->init = graph_channel_area_init;
656         art->draw = graph_channel_area_draw;
657         
658         BLI_addhead(&st->regiontypes, art);
659         
660         /* regions: UI buttons */
661         art = MEM_callocN(sizeof(ARegionType), "spacetype graphedit region");
662         art->regionid = RGN_TYPE_UI;
663         art->prefsizex = 200;
664         art->keymapflag = ED_KEYMAP_UI;
665         art->listener = graph_region_listener;
666         art->init = graph_buttons_area_init;
667         art->draw = graph_buttons_area_draw;
668         
669         BLI_addhead(&st->regiontypes, art);
670
671         graph_buttons_register(art);
672         
673         BKE_spacetype_register(st);
674 }
675