a623c5aae3a1125e61876f0b1a54b810f525fbcd
[blender-staging.git] / source / blender / editors / space_graph / space_graph.c
1 /**
2  * $Id:
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30 #include <stdio.h>
31
32 #include "DNA_anim_types.h"
33 #include "DNA_object_types.h"
34 #include "DNA_space_types.h"
35 #include "DNA_scene_types.h"
36 #include "DNA_screen_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
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 #include "BKE_utildefines.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_interface.h"
62 #include "UI_resources.h"
63 #include "UI_view2d.h"
64
65 #include "graph_intern.h"       // own include
66
67 /* ******************** manage regions ********************* */
68
69 ARegion *graph_has_buttons_region(ScrArea *sa)
70 {
71         ARegion *ar, *arnew;
72         
73         for (ar= sa->regionbase.first; ar; ar= ar->next) {
74                 if (ar->regiontype==RGN_TYPE_UI)
75                         return ar;
76         }
77         
78         /* add subdiv level; after main */
79         for (ar= sa->regionbase.first; ar; ar= ar->next) {
80                 if (ar->regiontype==RGN_TYPE_WINDOW)
81                         break;
82         }
83         
84         /* is error! */
85         if (ar==NULL) return NULL;
86         
87         arnew= MEM_callocN(sizeof(ARegion), "buttons for graph");
88         
89         BLI_insertlinkafter(&sa->regionbase, ar, arnew);
90         arnew->regiontype= RGN_TYPE_UI;
91         arnew->alignment= RGN_ALIGN_RIGHT;
92         
93         arnew->flag = RGN_FLAG_HIDDEN;
94         
95         return arnew;
96 }
97
98
99 /* ******************** default callbacks for ipo space ***************** */
100
101 static SpaceLink *graph_new(const bContext *C)
102 {
103         Scene *scene= CTX_data_scene(C);
104         ARegion *ar;
105         SpaceIpo *sipo;
106         
107         /* Graph Editor - general stuff */
108         sipo= MEM_callocN(sizeof(SpaceIpo), "init graphedit");
109         sipo->spacetype= SPACE_IPO;
110         
111         sipo->autosnap= SACTSNAP_FRAME;
112         
113         /* allocate DopeSheet data for Graph Editor */
114         sipo->ads= MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet");
115         sipo->ads->source= (ID *)scene;
116         
117         /* header */
118         ar= MEM_callocN(sizeof(ARegion), "header for graphedit");
119         
120         BLI_addtail(&sipo->regionbase, ar);
121         ar->regiontype= RGN_TYPE_HEADER;
122         ar->alignment= RGN_ALIGN_BOTTOM;
123         
124         /* channels */
125         ar= MEM_callocN(sizeof(ARegion), "channels area for graphedit");
126         
127         BLI_addtail(&sipo->regionbase, ar);
128         ar->regiontype= RGN_TYPE_CHANNELS;
129         ar->alignment= RGN_ALIGN_LEFT;
130         
131         ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
132         
133         /* ui buttons */
134         ar= MEM_callocN(sizeof(ARegion), "buttons area for graphedit");
135         
136         BLI_addtail(&sipo->regionbase, ar);
137         ar->regiontype= RGN_TYPE_UI;
138         ar->alignment= RGN_ALIGN_RIGHT;
139         ar->flag = RGN_FLAG_HIDDEN;
140         
141         /* main area */
142         ar= MEM_callocN(sizeof(ARegion), "main area for graphedit");
143         
144         BLI_addtail(&sipo->regionbase, ar);
145         ar->regiontype= RGN_TYPE_WINDOW;
146         
147         ar->v2d.tot.xmin= 0.0f;
148         ar->v2d.tot.ymin= (float)scene->r.sfra - 10.0f;
149         ar->v2d.tot.xmax= (float)scene->r.efra;
150         ar->v2d.tot.ymax= 10.0f;
151         
152         ar->v2d.cur= ar->v2d.tot;
153         
154         ar->v2d.min[0]= FLT_MIN;
155         ar->v2d.min[1]= FLT_MIN;
156
157         ar->v2d.max[0]= MAXFRAMEF;
158         ar->v2d.max[1]= FLT_MAX;
159         
160         ar->v2d.scroll= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
161         ar->v2d.scroll |= (V2D_SCROLL_LEFT|V2D_SCROLL_SCALE_VERTICAL);
162         
163         ar->v2d.keeptot= 0;
164         
165         return (SpaceLink *)sipo;
166 }
167
168 /* not spacelink itself */
169 static void graph_free(SpaceLink *sl)
170 {       
171         SpaceIpo *si= (SpaceIpo *)sl;
172         
173         if (si->ads) {
174                 BLI_freelistN(&si->ads->chanbase);
175                 MEM_freeN(si->ads);
176         }
177         
178         if (si->ghostCurves.first)
179                 free_fcurves(&si->ghostCurves);
180 }
181
182
183 /* spacetype; init callback */
184 static void graph_init(struct wmWindowManager *wm, ScrArea *sa)
185 {
186         SpaceIpo *sipo= (SpaceIpo *)sa->spacedata.first;
187         
188         /* init dopesheet data if non-existant (i.e. for old files) */
189         if (sipo->ads == NULL) {
190                 sipo->ads= MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet");
191                 sipo->ads->source= (ID *)(G.main->scene.first); // FIXME: this is a really nasty hack here for now...
192         }
193
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(C, v2d);
239         
240         /* grid */
241         unitx= (sipo->flag & SIPO_DRAWTIME)? V2D_UNIT_SECONDS : V2D_UNIT_FRAMESCALE;
242         grid= UI_view2d_grid_calc(C, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP, ar->winx, ar->winy);
243         UI_view2d_grid_draw(C, 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, grid);
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);
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(C, v2d, 1);
292         draw_markers_time(C, 0);
293         
294         /* preview range */
295         UI_view2d_view_ortho(C, 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         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
313         
314         /* own keymap */
315         keymap= WM_keymap_find(wm->defaultconf, "Animation Channels", 0, 0);
316         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
317         keymap= WM_keymap_find(wm->defaultconf, "Graph Editor Generic", SPACE_IPO, 0);
318         WM_event_add_keymap_handler(&ar->handlers, keymap);
319 }
320
321 static void graph_channel_area_draw(const bContext *C, ARegion *ar)
322 {
323         SpaceIpo *sipo= CTX_wm_space_graph(C);
324         bAnimContext ac;
325         View2D *v2d= &ar->v2d;
326         View2DScrollers *scrollers;
327         float col[3];
328         
329         /* clear and setup matrix */
330         UI_GetThemeColor3fv(TH_BACK, col);
331         glClearColor(col[0], col[1], col[2], 0.0);
332         glClear(GL_COLOR_BUFFER_BIT);
333         
334         UI_view2d_view_ortho(C, v2d);
335         
336         /* draw channels */
337         if (ANIM_animdata_get_context(C, &ac)) {
338                 graph_draw_channel_names((bContext*)C, &ac, sipo, ar);
339         }
340         
341         /* reset view matrix */
342         UI_view2d_view_restore(C);
343         
344         /* scrollers */
345         scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
346         UI_view2d_scrollers_draw(C, v2d, scrollers);
347         UI_view2d_scrollers_free(scrollers);
348 }
349
350 /* add handlers, stuff you only do once or on area/region changes */
351 static void graph_header_area_init(wmWindowManager *wm, ARegion *ar)
352 {
353         ED_region_header_init(ar);
354 }
355
356 static void graph_header_area_draw(const bContext *C, ARegion *ar)
357 {
358         ED_region_header(C, ar);
359 }
360
361 /* add handlers, stuff you only do once or on area/region changes */
362 static void graph_buttons_area_init(wmWindowManager *wm, ARegion *ar)
363 {
364         wmKeyMap *keymap;
365         
366         ED_region_panels_init(wm, ar);
367
368         keymap= WM_keymap_find(wm->defaultconf, "Graph Editor Generic", SPACE_IPO, 0);
369         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
370 }
371
372 static void graph_buttons_area_draw(const bContext *C, ARegion *ar)
373 {
374         ED_region_panels(C, ar, 1, NULL, -1);
375 }
376
377 static void graph_region_listener(ARegion *ar, wmNotifier *wmn)
378 {
379         /* context changes */
380         switch(wmn->category) {
381                 case NC_ANIMATION:
382                         ED_region_tag_redraw(ar);
383                         break;
384                 case NC_SCENE:
385                         switch(wmn->data) {
386                                 case ND_RENDER_OPTIONS:
387                                 case ND_OB_ACTIVE:
388                                 case ND_FRAME:
389                                 case ND_MARKERS:
390                                 case ND_SEQUENCER_SELECT:
391                                         ED_region_tag_redraw(ar);
392                                         break;
393                         }
394                         break;
395                 case NC_OBJECT:
396                         switch(wmn->data) {
397                                 case ND_BONE_ACTIVE:
398                                 case ND_BONE_SELECT:
399                                 case ND_KEYS:
400                                         ED_region_tag_redraw(ar);
401                                         break;
402                                 case ND_MODIFIER:
403                                         if(wmn->action == NA_RENAME)
404                                                 ED_region_tag_redraw(ar);
405                                         break;
406                         }
407                         break;
408                 case NC_NODE:
409                         switch(wmn->data) {
410                                 case ND_NODE_SELECT:
411                                         ED_region_tag_redraw(ar);
412                                         break;
413                         }
414                         switch(wmn->action) {
415                                 case NA_EDITED:
416                                         ED_region_tag_redraw(ar);
417                                         break;
418                         }
419                         break;
420                 case NC_ID:
421                         if(wmn->action == NA_RENAME)
422                                 ED_region_tag_redraw(ar);
423                         break;
424                 default:
425                         if(wmn->data==ND_KEYS)
426                                 ED_region_tag_redraw(ar);
427                                 
428         }
429 }
430
431 /* editor level listener */
432 static void graph_listener(ScrArea *sa, wmNotifier *wmn)
433 {
434         SpaceIpo *sipo= (SpaceIpo *)sa->spacedata.first;
435         
436         /* context changes */
437         switch (wmn->category) {
438                 case NC_ANIMATION:
439                         /* for selection changes of animation data, we can just redraw... otherwise autocolor might need to be done again */
440                         if (ELEM(wmn->data, ND_KEYFRAME_SELECT, ND_ANIMCHAN_SELECT))
441                                 ED_area_tag_redraw(sa);
442                         else
443                                 ED_area_tag_refresh(sa);
444                         break;
445                 case NC_SCENE:
446                         switch (wmn->data) {    
447                                 case ND_OB_ACTIVE:      /* selection changed, so force refresh to flush (needs flag set to do syncing)  */
448                                 case ND_OB_SELECT:
449                                         sipo->flag |= SIPO_TEMP_NEEDCHANSYNC;
450                                         ED_area_tag_refresh(sa);
451                                         break;
452                                         
453                                 default: /* just redrawing the view will do */
454                                         ED_area_tag_redraw(sa);
455                                         break;
456                         }
457                         break;
458                 case NC_OBJECT:
459                         switch (wmn->data) {
460                                 case ND_BONE_SELECT:    /* selection changed, so force refresh to flush (needs flag set to do syncing) */
461                                 case ND_BONE_ACTIVE:
462                                         sipo->flag |= SIPO_TEMP_NEEDCHANSYNC;
463                                         ED_area_tag_refresh(sa);
464                                         break;
465                                 case ND_VIEW3D_TRANSFORM:
466                                         break; /*do nothing*/                                   
467                                         
468                                 default: /* just redrawing the view will do */
469                                         ED_area_tag_redraw(sa);
470                                         break;
471                         }
472                         break;
473                 case NC_SPACE:
474                         if(wmn->data == ND_SPACE_GRAPH)
475                                 ED_area_tag_redraw(sa);
476                         break;
477                 
478                 // XXX: restore the case below if not enough updates occur...
479                 //default:
480                 //      if(wmn->data==ND_KEYS)
481                 //              ED_area_tag_redraw(sa);
482         }
483 }
484
485
486
487 static void graph_refresh(const bContext *C, ScrArea *sa)
488 {
489         SpaceIpo *sipo = (SpaceIpo *)sa->spacedata.first;
490         bAnimContext ac;
491         
492         /* updates to data needed depends on Graph Editor mode... */
493         switch (sipo->mode) {
494                 case SIPO_MODE_ANIMATION: /* all animation */
495                 {
496                         
497                 }
498                         break;
499                 
500                 case SIPO_MODE_DRIVERS: /* drivers only  */
501                 {
502                 
503                 }
504                         break; 
505         }
506         
507         /* region updates? */
508         // XXX resizing y-extents of tot should go here?
509         
510         /* update the state of the animchannels in response to changes from the data they represent 
511          * NOTE: the temp flag is used to indicate when this needs to be done, and will be cleared once handled
512          */
513         if (sipo->flag & SIPO_TEMP_NEEDCHANSYNC) {
514                 ANIM_sync_animchannels_to_data(C);
515                 sipo->flag &= ~SIPO_TEMP_NEEDCHANSYNC;
516         }
517         
518         /* init/adjust F-Curve colors */
519         if (ANIM_animdata_get_context(C, &ac)) {
520                 ListBase anim_data = {NULL, NULL};
521                 bAnimListElem *ale;
522                 int filter;
523                 int items, i;
524                 
525                 /* build list of F-Curves which will be visible as channels in channel-region
526                  *      - we don't include ANIMFILTER_CURVEVISIBLE filter, as that will result in a 
527                  *        mismatch between channel-colors and the drawn curves
528                  */
529                 filter= (ANIMFILTER_VISIBLE|ANIMFILTER_CURVESONLY);
530                 items= ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
531                 
532                 /* loop over F-Curves, assigning colors */
533                 for (ale=anim_data.first, i=0; ale; ale= ale->next, i++) {
534                         FCurve *fcu= (FCurve *)ale->data;
535                         
536                         /* set color of curve here */
537                         switch (fcu->color_mode) {
538                                 case FCURVE_COLOR_CUSTOM:
539                                         /* User has defined a custom color for this curve already (we assume it's not going to cause clashes with text colors),
540                                          * which should be left alone... Nothing needs to be done here.
541                                          */
542                                         break;
543                                         
544                                 case FCURVE_COLOR_AUTO_RGB:
545                                 {
546                                         /* F-Curve's array index is automatically mapped to RGB values. This works best of 3-value vectors. 
547                                          * TODO: find a way to module the hue so that not all curves have same color...
548                                          */
549                                         
550                                         /* standard table of colors to use */
551                                         const float _colorsets[4][3]= 
552                                         {
553                                                 {1.0f, 0.0f, 0.0f}, /* red */
554                                                 {0.0f, 1.0f, 0.0f}, /* green */
555                                                 {0.0f, 0.0f, 1.0f}, /* blue */
556                                                 {0.3f, 0.8f, 1.0f}, /* 'unknown' color - bluish so as to not conflict with handles */
557                                         };
558                                         
559                                         /* simply copy the relevant color over to the F-Curve */
560                                         if ((fcu->array_index >= 0) && (fcu->array_index < 3)) {
561                                                 /* if the index is within safe bounds, use index to access table */
562                                                 VECCOPY(fcu->color, _colorsets[fcu->array_index]);
563                                         }
564                                         else {
565                                                 /* use the 'unknown' color... */
566                                                 VECCOPY(fcu->color, _colorsets[3]);
567                                         }
568                                 }
569                                         break;
570                                 
571                                 case FCURVE_COLOR_AUTO_RAINBOW:
572                                 default:
573                                 {
574                                         /* determine color 'automatically' using 'magic function' which uses the given args
575                                          * of current item index + total items to determine some RGB color
576                                          */
577                                         getcolor_fcurve_rainbow(i, items, fcu->color);
578                                 }
579                                         break;
580                         }
581                 }
582                 
583                 /* free temp list */
584                 BLI_freelistN(&anim_data);
585         }
586 }
587
588 /* only called once, from space/spacetypes.c */
589 void ED_spacetype_ipo(void)
590 {
591         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype ipo");
592         ARegionType *art;
593         
594         st->spaceid= SPACE_IPO;
595         strncpy(st->name, "Graph", BKE_ST_MAXNAME);
596         
597         st->new= graph_new;
598         st->free= graph_free;
599         st->init= graph_init;
600         st->duplicate= graph_duplicate;
601         st->operatortypes= graphedit_operatortypes;
602         st->keymap= graphedit_keymap;
603         st->listener= graph_listener;
604         st->refresh= graph_refresh;
605         
606         /* regions: main window */
607         art= MEM_callocN(sizeof(ARegionType), "spacetype graphedit region");
608         art->regionid = RGN_TYPE_WINDOW;
609         art->init= graph_main_area_init;
610         art->draw= graph_main_area_draw;
611         art->listener= graph_region_listener;
612         art->keymapflag= ED_KEYMAP_VIEW2D/*|ED_KEYMAP_MARKERS*/|ED_KEYMAP_ANIMATION|ED_KEYMAP_FRAMES;
613
614         BLI_addhead(&st->regiontypes, art);
615         
616         /* regions: header */
617         art= MEM_callocN(sizeof(ARegionType), "spacetype graphedit region");
618         art->regionid = RGN_TYPE_HEADER;
619         art->minsizey= HEADERY;
620         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES|ED_KEYMAP_HEADER;
621         art->listener= graph_region_listener;
622         art->init= graph_header_area_init;
623         art->draw= graph_header_area_draw;
624         
625         BLI_addhead(&st->regiontypes, art);
626         
627         /* regions: channels */
628         art= MEM_callocN(sizeof(ARegionType), "spacetype graphedit region");
629         art->regionid = RGN_TYPE_CHANNELS;
630         art->minsizex= 200+V2D_SCROLL_WIDTH; /* 200 is the 'standard', but due to scrollers, we want a bit more to fit the lock icons in */
631         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES;
632         art->listener= graph_region_listener;
633         art->init= graph_channel_area_init;
634         art->draw= graph_channel_area_draw;
635         
636         BLI_addhead(&st->regiontypes, art);
637         
638         /* regions: UI buttons */
639         art= MEM_callocN(sizeof(ARegionType), "spacetype graphedit region");
640         art->regionid = RGN_TYPE_UI;
641         art->minsizex= 200;
642         art->keymapflag= ED_KEYMAP_UI;
643         art->listener= graph_region_listener;
644         art->init= graph_buttons_area_init;
645         art->draw= graph_buttons_area_draw;
646         
647         BLI_addhead(&st->regiontypes, art);
648
649         graph_buttons_register(art);
650         
651         BKE_spacetype_register(st);
652 }
653