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