ef6cb1980083b4f18c7d5d62f44a04e666e91bf9
[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         /* XXX: but, don't do SIPO_TEMP_NEEDCHANSYNC (i.e. channel select state sync)
193          * as this is run on each region resize; setting this here will cause selection
194          * state to be lost on area/region resizing. [#35744]
195          */
196         ED_area_tag_refresh(sa);
197 }
198
199 static SpaceLink *graph_duplicate(SpaceLink *sl)
200 {
201         SpaceIpo *sipon = MEM_dupallocN(sl);
202         
203         /* clear or remove stuff from old */
204         BLI_duplicatelist(&sipon->ghostCurves, &((SpaceIpo *)sl)->ghostCurves);
205         sipon->ads = MEM_dupallocN(sipon->ads);
206         
207         return (SpaceLink *)sipon;
208 }
209
210 /* add handlers, stuff you only do once or on area/region changes */
211 static void graph_main_area_init(wmWindowManager *wm, ARegion *ar)
212 {
213         wmKeyMap *keymap;
214         
215         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
216         
217         /* own keymap */
218         keymap = WM_keymap_find(wm->defaultconf, "Graph Editor", SPACE_IPO, 0);
219         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
220         keymap = WM_keymap_find(wm->defaultconf, "Graph Editor Generic", SPACE_IPO, 0);
221         WM_event_add_keymap_handler(&ar->handlers, keymap);
222 }
223
224 static void graph_main_area_draw(const bContext *C, ARegion *ar)
225 {
226         /* draw entirely, view changes should be handled here */
227         SpaceIpo *sipo = CTX_wm_space_graph(C);
228         bAnimContext ac;
229         View2D *v2d = &ar->v2d;
230         View2DGrid *grid;
231         View2DScrollers *scrollers;
232         float col[3];
233         short unitx = 0, unity = V2D_UNIT_VALUES, flag = 0;
234         
235         /* clear and setup matrix */
236         UI_GetThemeColor3fv(TH_BACK, col);
237         glClearColor(col[0], col[1], col[2], 0.0);
238         glClear(GL_COLOR_BUFFER_BIT);
239         
240         UI_view2d_view_ortho(v2d);
241         
242         /* grid */
243         unitx = (sipo->flag & SIPO_DRAWTIME) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMESCALE;
244         grid = UI_view2d_grid_calc(CTX_data_scene(C), v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP, ar->winx, ar->winy);
245         UI_view2d_grid_draw(v2d, grid, V2D_GRIDLINES_ALL);
246         
247         ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
248
249         /* draw data */
250         if (ANIM_animdata_get_context(C, &ac)) {
251                 /* draw ghost curves */
252                 graph_draw_ghost_curves(&ac, sipo, ar);
253                 
254                 /* draw curves twice - unselected, then selected, so that the are fewer occlusion problems */
255                 graph_draw_curves(&ac, sipo, ar, grid, 0);
256                 graph_draw_curves(&ac, sipo, ar, grid, 1);
257                 
258                 /* XXX the slow way to set tot rect... but for nice sliders needed (ton) */
259                 get_graph_keyframe_extents(&ac, &v2d->tot.xmin, &v2d->tot.xmax, &v2d->tot.ymin, &v2d->tot.ymax, false, true);
260                 /* extra offset so that these items are visible */
261                 v2d->tot.xmin -= 10.0f;
262                 v2d->tot.xmax += 10.0f;
263         }
264         
265         /* only free grid after drawing data, as we need to use it to determine sampling rate */
266         UI_view2d_grid_free(grid);
267         
268         /* horizontal component of value-cursor (value line before the current frame line) */
269         if ((sipo->flag & SIPO_NODRAWCURSOR) == 0) {
270                 float vec[2];
271                 
272                 /* Draw a green line to indicate the cursor value */
273                 vec[1] = sipo->cursorVal;
274                 
275                 UI_ThemeColorShadeAlpha(TH_CFRAME, -10, -50);
276                 glLineWidth(2.0);
277                 
278                 glEnable(GL_BLEND);
279                 glBegin(GL_LINE_STRIP);
280                 vec[0] = v2d->cur.xmin;
281                 glVertex2fv(vec);
282                         
283                 vec[0] = v2d->cur.xmax;
284                 glVertex2fv(vec);
285                 glEnd(); // GL_LINE_STRIP
286                 glDisable(GL_BLEND);
287         }
288         
289         /* current frame */
290         if (sipo->flag & SIPO_DRAWTIME) flag |= DRAWCFRA_UNIT_SECONDS;
291         if ((sipo->flag & SIPO_NODRAWCFRANUM) == 0) flag |= DRAWCFRA_SHOW_NUMBOX;
292         ANIM_draw_cfra(C, v2d, flag);
293         
294         /* markers */
295         UI_view2d_view_orthoSpecial(ar, v2d, 1);
296         ED_markers_draw(C, DRAW_MARKERS_MARGIN);
297         
298         /* preview range */
299         UI_view2d_view_ortho(v2d);
300         ANIM_draw_previewrange(C, v2d, 0);
301         
302         /* callback */
303         UI_view2d_view_ortho(v2d);
304         ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
305
306         /* reset view matrix */
307         UI_view2d_view_restore(C);
308         
309         /* scrollers */
310         // FIXME: args for scrollers depend on the type of data being shown...
311         scrollers = UI_view2d_scrollers_calc(C, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP);
312         UI_view2d_scrollers_draw(C, v2d, scrollers);
313         UI_view2d_scrollers_free(scrollers);
314 }
315
316 static void graph_channel_area_init(wmWindowManager *wm, ARegion *ar)
317 {
318         wmKeyMap *keymap;
319         
320         /* make sure we keep the hide flags */
321         ar->v2d.scroll |= (V2D_SCROLL_RIGHT | V2D_SCROLL_BOTTOM);
322         ar->v2d.scroll &= ~(V2D_SCROLL_LEFT | V2D_SCROLL_TOP);  /* prevent any noise of past */
323         ar->v2d.scroll |= V2D_SCROLL_HORIZONTAL_HIDE;
324         ar->v2d.scroll |= V2D_SCROLL_VERTICAL_HIDE;
325         
326         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
327         
328         /* own keymap */
329         keymap = WM_keymap_find(wm->defaultconf, "Animation Channels", 0, 0);
330         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
331         keymap = WM_keymap_find(wm->defaultconf, "Graph Editor Generic", SPACE_IPO, 0);
332         WM_event_add_keymap_handler(&ar->handlers, keymap);
333 }
334
335 static void graph_channel_area_draw(const bContext *C, ARegion *ar)
336 {
337         bAnimContext ac;
338         View2D *v2d = &ar->v2d;
339         View2DScrollers *scrollers;
340         float col[3];
341         
342         /* clear and setup matrix */
343         UI_GetThemeColor3fv(TH_BACK, col);
344         glClearColor(col[0], col[1], col[2], 0.0);
345         glClear(GL_COLOR_BUFFER_BIT);
346         
347         UI_view2d_view_ortho(v2d);
348         
349         /* draw channels */
350         if (ANIM_animdata_get_context(C, &ac)) {
351                 graph_draw_channel_names((bContext *)C, &ac, ar);
352         }
353         
354         /* reset view matrix */
355         UI_view2d_view_restore(C);
356         
357         /* scrollers */
358         scrollers = UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
359         UI_view2d_scrollers_draw(C, v2d, scrollers);
360         UI_view2d_scrollers_free(scrollers);
361 }
362
363 /* add handlers, stuff you only do once or on area/region changes */
364 static void graph_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar)
365 {
366         ED_region_header_init(ar);
367 }
368
369 static void graph_header_area_draw(const bContext *C, ARegion *ar)
370 {
371         ED_region_header(C, ar);
372 }
373
374 /* add handlers, stuff you only do once or on area/region changes */
375 static void graph_buttons_area_init(wmWindowManager *wm, ARegion *ar)
376 {
377         wmKeyMap *keymap;
378         
379         ED_region_panels_init(wm, ar);
380
381         keymap = WM_keymap_find(wm->defaultconf, "Graph Editor Generic", SPACE_IPO, 0);
382         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
383 }
384
385 static void graph_buttons_area_draw(const bContext *C, ARegion *ar)
386 {
387         ED_region_panels(C, ar, 1, NULL, -1);
388 }
389
390 static void graph_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
391 {
392         /* context changes */
393         switch (wmn->category) {
394                 case NC_ANIMATION:
395                         ED_region_tag_redraw(ar);
396                         break;
397                 case NC_SCENE:
398                         switch (wmn->data) {
399                                 case ND_RENDER_OPTIONS:
400                                 case ND_OB_ACTIVE:
401                                 case ND_FRAME:
402                                 case ND_MARKERS:
403                                         ED_region_tag_redraw(ar);
404                                         break;
405                                 case ND_SEQUENCER:
406                                         if (wmn->action == NA_SELECTED)
407                                                 ED_region_tag_redraw(ar);
408                                         break;
409                         }
410                         break;
411                 case NC_OBJECT:
412                         switch (wmn->data) {
413                                 case ND_BONE_ACTIVE:
414                                 case ND_BONE_SELECT:
415                                 case ND_KEYS:
416                                         ED_region_tag_redraw(ar);
417                                         break;
418                                 case ND_MODIFIER:
419                                         if (wmn->action == NA_RENAME)
420                                                 ED_region_tag_redraw(ar);
421                                         break;
422                         }
423                         break;
424                 case NC_NODE:
425                         switch (wmn->action) {
426                                 case NA_EDITED:
427                                 case NA_SELECTED:
428                                         ED_region_tag_redraw(ar);
429                                         break;
430                         }
431                         break;
432                 case NC_ID:
433                         if (wmn->action == NA_RENAME)
434                                 ED_region_tag_redraw(ar);
435                         break;
436                 default:
437                         if (wmn->data == ND_KEYS)
438                                 ED_region_tag_redraw(ar);
439                         break;
440                                 
441         }
442 }
443
444 /* editor level listener */
445 static void graph_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn)
446 {
447         SpaceIpo *sipo = (SpaceIpo *)sa->spacedata.first;
448         
449         /* context changes */
450         switch (wmn->category) {
451                 case NC_ANIMATION:
452                         /* for selection changes of animation data, we can just redraw... otherwise autocolor might need to be done again */
453                         if (ELEM(wmn->data, ND_KEYFRAME, ND_ANIMCHAN) && (wmn->action == NA_SELECTED))
454                                 ED_area_tag_redraw(sa);
455                         else
456                                 ED_area_tag_refresh(sa);
457                         break;
458                 case NC_SCENE:
459                         switch (wmn->data) {
460                                 case ND_OB_ACTIVE:  /* selection changed, so force refresh to flush (needs flag set to do syncing)  */
461                                 case ND_OB_SELECT:
462                                         sipo->flag |= SIPO_TEMP_NEEDCHANSYNC;
463                                         ED_area_tag_refresh(sa);
464                                         break;
465                                         
466                                 default: /* just redrawing the view will do */
467                                         ED_area_tag_redraw(sa);
468                                         break;
469                         }
470                         break;
471                 case NC_OBJECT:
472                         switch (wmn->data) {
473                                 case ND_BONE_SELECT:    /* selection changed, so force refresh to flush (needs flag set to do syncing) */
474                                 case ND_BONE_ACTIVE:
475                                         sipo->flag |= SIPO_TEMP_NEEDCHANSYNC;
476                                         ED_area_tag_refresh(sa);
477                                         break;
478                                 case ND_TRANSFORM:
479                                         break; /*do nothing*/
480                                         
481                                 default: /* just redrawing the view will do */
482                                         ED_area_tag_redraw(sa);
483                                         break;
484                         }
485                         break;
486                 case NC_NODE:
487                         if (wmn->action == NA_SELECTED) {
488                                 /* selection changed, so force refresh to flush (needs flag set to do syncing) */
489                                 sipo->flag |= SIPO_TEMP_NEEDCHANSYNC;
490                                 ED_area_tag_refresh(sa);
491                         }
492                         break;
493                 case NC_SPACE:
494                         if (wmn->data == ND_SPACE_GRAPH)
495                                 ED_area_tag_redraw(sa);
496                         break;
497                 case NC_WINDOW:
498                         if (sipo->flag & SIPO_TEMP_NEEDCHANSYNC) {
499                                 /* force redraw/refresh after undo/redo - prevents "black curve" problem */
500                                 ED_area_tag_refresh(sa);
501                         }
502                         break;
503                         
504                         // XXX: restore the case below if not enough updates occur...
505                         //default:
506                         //      if (wmn->data == ND_KEYS)
507                         //              ED_area_tag_redraw(sa);
508         }
509 }
510
511
512
513 static void graph_refresh(const bContext *C, ScrArea *sa)
514 {
515         SpaceIpo *sipo = (SpaceIpo *)sa->spacedata.first;
516         bAnimContext ac;
517         
518         /* updates to data needed depends on Graph Editor mode... */
519         switch (sipo->mode) {
520                 case SIPO_MODE_ANIMATION: /* all animation */
521                 {
522                         break;
523                 }
524                 
525                 case SIPO_MODE_DRIVERS: /* drivers only  */
526                 {
527                         break;
528                 }
529         }
530         
531         /* region updates? */
532         // XXX re-sizing y-extents of tot should go here?
533         
534         /* update the state of the animchannels in response to changes from the data they represent 
535          * NOTE: the temp flag is used to indicate when this needs to be done, and will be cleared once handled
536          */
537         if (sipo->flag & SIPO_TEMP_NEEDCHANSYNC) {
538                 ANIM_sync_animchannels_to_data(C);
539                 sipo->flag &= ~SIPO_TEMP_NEEDCHANSYNC;
540                 ED_area_tag_redraw(sa);
541         }
542         
543         /* init/adjust F-Curve colors */
544         if (ANIM_animdata_get_context(C, &ac)) {
545                 ListBase anim_data = {NULL, NULL};
546                 bAnimListElem *ale;
547                 size_t items;
548                 int filter;
549                 int i;
550                 
551                 UI_SetTheme(SPACE_IPO, RGN_TYPE_WINDOW);
552
553                 /* build list of F-Curves which will be visible as channels in channel-region
554                  *  - we don't include ANIMFILTER_CURVEVISIBLE filter, as that will result in a
555                  *    mismatch between channel-colors and the drawn curves
556                  */
557                 filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_NODUPLIS);
558                 items = ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
559                 
560                 /* loop over F-Curves, assigning colors */
561                 for (ale = anim_data.first, i = 0; ale; ale = ale->next, i++) {
562                         FCurve *fcu = (FCurve *)ale->data;
563                         
564                         /* set color of curve here */
565                         switch (fcu->color_mode) {
566                                 case FCURVE_COLOR_CUSTOM:
567                                 {
568                                         /* User has defined a custom color for this curve already (we assume it's not going to cause clashes with text colors),
569                                          * which should be left alone... Nothing needs to be done here.
570                                          */
571                                         break;
572                                 }
573                                 case FCURVE_COLOR_AUTO_RGB:
574                                 {
575                                         /* F-Curve's array index is automatically mapped to RGB values. This works best of 3-value vectors. 
576                                          * TODO: find a way to module the hue so that not all curves have same color...
577                                          */
578                                         float *col = fcu->color;
579                                         
580                                         switch (fcu->array_index) {
581                                                 case 0:
582                                                         UI_GetThemeColor3fv(TH_AXIS_X, col);
583                                                         break;
584                                                 case 1:
585                                                         UI_GetThemeColor3fv(TH_AXIS_Y, col);
586                                                         break;
587                                                 case 2:
588                                                         UI_GetThemeColor3fv(TH_AXIS_Z, col);
589                                                         break;
590                                                 default:
591                                                         /* 'unknown' color - bluish so as to not conflict with handles */
592                                                         col[0] = 0.3f; col[1] = 0.8f; col[2] = 1.0f;
593                                                         break;
594                                         }
595                                         break;
596                                 }
597                                 case FCURVE_COLOR_AUTO_RAINBOW:
598                                 default:
599                                 {
600                                         /* determine color 'automatically' using 'magic function' which uses the given args
601                                          * of current item index + total items to determine some RGB color
602                                          */
603                                         getcolor_fcurve_rainbow(i, items, fcu->color);
604                                         break;
605                                 }
606                         }
607                 }
608                 
609                 /* free temp list */
610                 ANIM_animdata_freelist(&anim_data);
611         }
612 }
613
614 /* only called once, from space/spacetypes.c */
615 void ED_spacetype_ipo(void)
616 {
617         SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype ipo");
618         ARegionType *art;
619         
620         st->spaceid = SPACE_IPO;
621         strncpy(st->name, "Graph", BKE_ST_MAXNAME);
622         
623         st->new = graph_new;
624         st->free = graph_free;
625         st->init = graph_init;
626         st->duplicate = graph_duplicate;
627         st->operatortypes = graphedit_operatortypes;
628         st->keymap = graphedit_keymap;
629         st->listener = graph_listener;
630         st->refresh = graph_refresh;
631         
632         /* regions: main window */
633         art = MEM_callocN(sizeof(ARegionType), "spacetype graphedit region");
634         art->regionid = RGN_TYPE_WINDOW;
635         art->init = graph_main_area_init;
636         art->draw = graph_main_area_draw;
637         art->listener = graph_region_listener;
638         art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_MARKERS | ED_KEYMAP_ANIMATION | ED_KEYMAP_FRAMES;
639
640         BLI_addhead(&st->regiontypes, art);
641         
642         /* regions: header */
643         art = MEM_callocN(sizeof(ARegionType), "spacetype graphedit region");
644         art->regionid = RGN_TYPE_HEADER;
645         art->prefsizey = HEADERY;
646         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER;
647         art->listener = graph_region_listener;
648         art->init = graph_header_area_init;
649         art->draw = graph_header_area_draw;
650         
651         BLI_addhead(&st->regiontypes, art);
652         
653         /* regions: channels */
654         art = MEM_callocN(sizeof(ARegionType), "spacetype graphedit region");
655         art->regionid = RGN_TYPE_CHANNELS;
656         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 */
657         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES;
658         art->listener = graph_region_listener;
659         art->init = graph_channel_area_init;
660         art->draw = graph_channel_area_draw;
661         
662         BLI_addhead(&st->regiontypes, art);
663         
664         /* regions: UI buttons */
665         art = MEM_callocN(sizeof(ARegionType), "spacetype graphedit region");
666         art->regionid = RGN_TYPE_UI;
667         art->prefsizex = 200;
668         art->keymapflag = ED_KEYMAP_UI;
669         art->listener = graph_region_listener;
670         art->init = graph_buttons_area_init;
671         art->draw = graph_buttons_area_draw;
672         
673         BLI_addhead(&st->regiontypes, art);
674
675         graph_buttons_register(art);
676         
677         BKE_spacetype_register(st);
678 }
679