Dopesheet: Keyframe size can be adjusted as part of theme settings
[blender.git] / source / blender / editors / space_action / space_action.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_action/space_action.c
28  *  \ingroup spaction
29  */
30
31
32 #include <string.h>
33 #include <stdio.h>
34
35 #include "DNA_action_types.h"
36 #include "DNA_group_types.h"
37 #include "DNA_scene_types.h"
38
39 #include "MEM_guardedalloc.h"
40
41 #include "BLI_blenlib.h"
42 #include "BLI_math.h"
43 #include "BLI_utildefines.h"
44
45 #include "BKE_context.h"
46 #include "BKE_screen.h"
47
48 #include "BIF_gl.h"
49
50 #include "WM_api.h"
51 #include "WM_types.h"
52
53 #include "UI_resources.h"
54 #include "UI_view2d.h"
55
56 #include "ED_space_api.h"
57 #include "ED_screen.h"
58 #include "ED_anim_api.h"
59 #include "ED_markers.h"
60
61 #include "action_intern.h"  /* own include */
62
63 /* ******************** manage regions ********************* */
64
65 ARegion *action_has_buttons_region(ScrArea *sa)
66 {
67         ARegion *ar, *arnew;
68         
69         ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
70         if (ar) return ar;
71         
72         /* add subdiv level; after main */
73         ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
74         
75         /* is error! */
76         if (ar == NULL) return NULL;
77         
78         arnew = MEM_callocN(sizeof(ARegion), "buttons for action");
79         
80         BLI_insertlinkafter(&sa->regionbase, ar, arnew);
81         arnew->regiontype = RGN_TYPE_UI;
82         arnew->alignment = RGN_ALIGN_RIGHT;
83         
84         arnew->flag = RGN_FLAG_HIDDEN;
85         
86         return arnew;
87 }
88
89 /* ******************** default callbacks for action space ***************** */
90
91 static SpaceLink *action_new(const bContext *C)
92 {
93         Scene *scene = CTX_data_scene(C);
94         ScrArea *sa = CTX_wm_area(C);
95         SpaceAction *saction;
96         ARegion *ar;
97         
98         saction = MEM_callocN(sizeof(SpaceAction), "initaction");
99         saction->spacetype = SPACE_ACTION;
100         
101         saction->autosnap = SACTSNAP_FRAME;
102         saction->mode = SACTCONT_DOPESHEET;
103         
104         saction->ads.filterflag |= ADS_FILTER_SUMMARY;
105         
106         /* header */
107         ar = MEM_callocN(sizeof(ARegion), "header for action");
108         
109         BLI_addtail(&saction->regionbase, ar);
110         ar->regiontype = RGN_TYPE_HEADER;
111         ar->alignment = RGN_ALIGN_BOTTOM;
112         
113         /* channel list region */
114         ar = MEM_callocN(sizeof(ARegion), "channel region for action");
115         BLI_addtail(&saction->regionbase, ar);
116         ar->regiontype = RGN_TYPE_CHANNELS;
117         ar->alignment = RGN_ALIGN_LEFT;
118         
119         /* only need to set scroll settings, as this will use 'listview' v2d configuration */
120         ar->v2d.scroll = V2D_SCROLL_BOTTOM;
121         ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
122         
123         /* ui buttons */
124         ar = MEM_callocN(sizeof(ARegion), "buttons region for action");
125         
126         BLI_addtail(&saction->regionbase, ar);
127         ar->regiontype = RGN_TYPE_UI;
128         ar->alignment = RGN_ALIGN_RIGHT;
129         ar->flag = RGN_FLAG_HIDDEN;
130         
131         /* main region */
132         ar = MEM_callocN(sizeof(ARegion), "main region for action");
133         
134         BLI_addtail(&saction->regionbase, ar);
135         ar->regiontype = RGN_TYPE_WINDOW;
136         
137         ar->v2d.tot.xmin = (float)(SFRA - 10);
138         ar->v2d.tot.ymin = (float)(-sa->winy) / 3.0f;
139         ar->v2d.tot.xmax = (float)(EFRA + 10);
140         ar->v2d.tot.ymax = 0.0f;
141         
142         ar->v2d.cur = ar->v2d.tot;
143         
144         ar->v2d.min[0] = 0.0f;
145         ar->v2d.min[1] = 0.0f;
146         
147         ar->v2d.max[0] = MAXFRAMEF;
148         ar->v2d.max[1] = FLT_MAX;
149
150         ar->v2d.minzoom = 0.01f;
151         ar->v2d.maxzoom = 50;
152         ar->v2d.scroll = (V2D_SCROLL_BOTTOM | V2D_SCROLL_SCALE_HORIZONTAL);
153         ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
154         ar->v2d.keepzoom = V2D_LOCKZOOM_Y;
155         ar->v2d.keepofs = V2D_KEEPOFS_Y;
156         ar->v2d.align = V2D_ALIGN_NO_POS_Y;
157         ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
158         
159         return (SpaceLink *)saction;
160 }
161
162 /* not spacelink itself */
163 static void action_free(SpaceLink *UNUSED(sl))
164 {       
165 //      SpaceAction *saction = (SpaceAction *) sl;
166 }
167
168
169 /* spacetype; init callback */
170 static void action_init(struct wmWindowManager *UNUSED(wm), ScrArea *sa)
171 {
172         SpaceAction *saction = sa->spacedata.first;
173         saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
174 }
175
176 static SpaceLink *action_duplicate(SpaceLink *sl)
177 {
178         SpaceAction *sactionn = MEM_dupallocN(sl);
179         
180         /* clear or remove stuff from old */
181         
182         return (SpaceLink *)sactionn;
183 }
184
185
186
187 /* add handlers, stuff you only do once or on area/region changes */
188 static void action_main_region_init(wmWindowManager *wm, ARegion *ar)
189 {
190         wmKeyMap *keymap;
191         
192         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
193         
194         /* own keymap */
195         keymap = WM_keymap_find(wm->defaultconf, "Dopesheet", SPACE_ACTION, 0);
196         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
197         keymap = WM_keymap_find(wm->defaultconf, "Dopesheet Generic", SPACE_ACTION, 0);
198         WM_event_add_keymap_handler(&ar->handlers, keymap);
199 }
200
201 static void action_main_region_draw(const bContext *C, ARegion *ar)
202 {
203         /* draw entirely, view changes should be handled here */
204         SpaceAction *saction = CTX_wm_space_action(C);
205         bAnimContext ac;
206         View2D *v2d = &ar->v2d;
207         View2DGrid *grid;
208         View2DScrollers *scrollers;
209         short unit = 0, flag = 0;
210         
211         /* clear and setup matrix */
212         UI_ThemeClearColor(TH_BACK);
213         glClear(GL_COLOR_BUFFER_BIT);
214         
215         UI_view2d_view_ortho(v2d);
216         
217         /* time grid */
218         unit = (saction->flag & SACTION_DRAWTIME) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMES;
219         grid = UI_view2d_grid_calc(CTX_data_scene(C), v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY, ar->winx, ar->winy);
220         UI_view2d_grid_draw(v2d, grid, V2D_GRIDLINES_ALL);
221         UI_view2d_grid_free(grid);
222         
223         ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
224
225         /* data */
226         if (ANIM_animdata_get_context(C, &ac)) {
227                 draw_channel_strips(&ac, saction, ar);
228         }
229         
230         /* current frame */
231         if (saction->flag & SACTION_DRAWTIME) flag |= DRAWCFRA_UNIT_SECONDS;
232         if ((saction->flag & SACTION_NODRAWCFRANUM) == 0) flag |= DRAWCFRA_SHOW_NUMBOX;
233         ANIM_draw_cfra(C, v2d, flag);
234         
235         /* markers */
236         UI_view2d_view_orthoSpecial(ar, v2d, 1);
237         
238         flag = ((ac.markers && (ac.markers != &ac.scene->markers)) ? DRAW_MARKERS_LOCAL : 0) | DRAW_MARKERS_MARGIN;
239         ED_markers_draw(C, flag);
240         
241         /* preview range */
242         UI_view2d_view_ortho(v2d);
243         ANIM_draw_previewrange(C, v2d, 0);
244
245         /* callback */
246         UI_view2d_view_ortho(v2d);
247         ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
248         
249         /* reset view matrix */
250         UI_view2d_view_restore(C);
251         
252         /* scrollers */
253         scrollers = UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
254         UI_view2d_scrollers_draw(C, v2d, scrollers);
255         UI_view2d_scrollers_free(scrollers);
256 }
257
258 /* add handlers, stuff you only do once or on area/region changes */
259 static void action_channel_region_init(wmWindowManager *wm, ARegion *ar)
260 {
261         wmKeyMap *keymap;
262         
263         /* ensure the 2d view sync works - main region has bottom scroller */
264         ar->v2d.scroll = V2D_SCROLL_BOTTOM;
265         
266         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
267         
268         /* own keymap */
269         keymap = WM_keymap_find(wm->defaultconf, "Animation Channels", 0, 0);
270         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
271         
272         keymap = WM_keymap_find(wm->defaultconf, "Dopesheet Generic", SPACE_ACTION, 0);
273         WM_event_add_keymap_handler(&ar->handlers, keymap);
274 }
275
276 static void action_channel_region_draw(const bContext *C, ARegion *ar)
277 {
278         /* draw entirely, view changes should be handled here */
279         bAnimContext ac;
280         View2D *v2d = &ar->v2d;
281         
282         /* clear and setup matrix */
283         UI_ThemeClearColor(TH_BACK);
284         glClear(GL_COLOR_BUFFER_BIT);
285         
286         UI_view2d_view_ortho(v2d);
287         
288         /* data */
289         if (ANIM_animdata_get_context(C, &ac)) {
290                 draw_channel_names((bContext *)C, &ac, ar);
291         }
292         
293         /* reset view matrix */
294         UI_view2d_view_restore(C);
295         
296         /* no scrollers here */
297 }
298
299
300 /* add handlers, stuff you only do once or on area/region changes */
301 static void action_header_region_init(wmWindowManager *UNUSED(wm), ARegion *ar)
302 {
303         ED_region_header_init(ar);
304 }
305
306 static void action_header_region_draw(const bContext *C, ARegion *ar)
307 {
308         ED_region_header(C, ar);
309 }
310
311 static void action_channel_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
312 {
313         /* context changes */
314         switch (wmn->category) {
315                 case NC_ANIMATION:
316                         ED_region_tag_redraw(ar);
317                         break;
318                 case NC_SCENE:
319                         switch (wmn->data) {
320                                 case ND_OB_ACTIVE:
321                                 case ND_FRAME:
322                                         ED_region_tag_redraw(ar);
323                                         break;
324                         }
325                         break;
326                 case NC_OBJECT:
327                         switch (wmn->data) {
328                                 case ND_BONE_ACTIVE:
329                                 case ND_BONE_SELECT:
330                                 case ND_KEYS:
331                                         ED_region_tag_redraw(ar);
332                                         break;
333                                 case ND_MODIFIER:
334                                         if (wmn->action == NA_RENAME)
335                                                 ED_region_tag_redraw(ar);
336                                         break;
337                         }
338                         break;
339                 case NC_GPENCIL:
340                         if (wmn->action == NA_RENAME)
341                                 ED_region_tag_redraw(ar);
342                         break;
343                 case NC_ID:
344                         if (wmn->action == NA_RENAME)
345                                 ED_region_tag_redraw(ar);
346                         break;
347                 default:
348                         if (wmn->data == ND_KEYS)
349                                 ED_region_tag_redraw(ar);
350                         break;
351         }
352 }
353
354 static void action_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
355 {
356         /* context changes */
357         switch (wmn->category) {
358                 case NC_ANIMATION:
359                         ED_region_tag_redraw(ar);
360                         break;
361                 case NC_SCENE:
362                         switch (wmn->data) {
363                                 case ND_RENDER_OPTIONS:
364                                 case ND_OB_ACTIVE:
365                                 case ND_FRAME:
366                                 case ND_MARKERS:
367                                         ED_region_tag_redraw(ar);
368                                         break;
369                         }
370                         break;
371                 case NC_OBJECT:
372                         switch (wmn->data) {
373                                 case ND_TRANSFORM:
374                                         /* moving object shouldn't need to redraw action */
375                                         break;
376                                 case ND_BONE_ACTIVE:
377                                 case ND_BONE_SELECT:
378                                 case ND_KEYS:
379                                         ED_region_tag_redraw(ar);
380                                         break;
381                         }
382                         break;
383                 case NC_NODE:
384                         switch (wmn->action) {
385                                 case NA_EDITED:
386                                         ED_region_tag_redraw(ar);
387                                         break;
388                         }
389                         break;
390                 case NC_ID:
391                         if (wmn->action == NA_RENAME)
392                                 ED_region_tag_redraw(ar);
393                         break;
394                                 
395                 default:
396                         if (wmn->data == ND_KEYS)
397                                 ED_region_tag_redraw(ar);
398                         break;
399         }
400 }
401
402 /* editor level listener */
403 static void action_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn)
404 {
405         SpaceAction *saction = (SpaceAction *)sa->spacedata.first;
406         
407         /* context changes */
408         switch (wmn->category) {
409                 case NC_GPENCIL:
410                         if (wmn->action == NA_EDITED) {
411                                 /* only handle this event in GPencil mode for performance considerations */
412                                 if (saction->mode == SACTCONT_GPENCIL)
413                                         ED_area_tag_redraw(sa);
414                         }
415                         break;
416                 case NC_ANIMATION:
417                         /* for NLA tweakmode enter/exit, need complete refresh */
418                         if (wmn->data == ND_NLA_ACTCHANGE) {
419                                 saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
420                                 ED_area_tag_refresh(sa);
421                         }
422                         /* autocolor only really needs to change when channels are added/removed, or previously hidden stuff appears 
423                          * (assume for now that if just adding these works, that will be fine)
424                          */
425                         else if (((wmn->data == ND_KEYFRAME) && ELEM(wmn->action, NA_ADDED, NA_REMOVED)) ||
426                                  ((wmn->data == ND_ANIMCHAN) && (wmn->action != NA_SELECTED)))
427                         {
428                                 ED_area_tag_refresh(sa);
429                         }
430                         /* for simple edits to the curve data though (or just plain selections), a simple redraw should work 
431                          * (see T39851 for an example of how this can go wrong)
432                          */
433                         else {
434                                 ED_area_tag_redraw(sa);
435                         }
436                         break;
437                 case NC_SCENE:
438                         switch (wmn->data) {
439                                 case ND_OB_ACTIVE:  /* selection changed, so force refresh to flush (needs flag set to do syncing) */
440                                 case ND_OB_SELECT:
441                                         saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
442                                         ED_area_tag_refresh(sa);
443                                         break;
444                                         
445                                 default: /* just redrawing the view will do */
446                                         ED_area_tag_redraw(sa);
447                                         break;
448                         }
449                         break;
450                 case NC_OBJECT:
451                         switch (wmn->data) {
452                                 case ND_BONE_SELECT:    /* selection changed, so force refresh to flush (needs flag set to do syncing) */
453                                 case ND_BONE_ACTIVE:
454                                         saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
455                                         ED_area_tag_refresh(sa);
456                                         break;
457                                 case ND_TRANSFORM:
458                                         /* moving object shouldn't need to redraw action */
459                                         break;
460                                 default: /* just redrawing the view will do */
461                                         ED_area_tag_redraw(sa);
462                                         break;
463                         }
464                         break;
465                 case NC_MASK:
466                         if (saction->mode == SACTCONT_MASK) {
467                                 switch (wmn->data) {
468                                         case ND_DATA:
469                                                 ED_area_tag_refresh(sa);
470                                                 ED_area_tag_redraw(sa);
471                                                 break;
472                                         default: /* just redrawing the view will do */
473                                                 ED_area_tag_redraw(sa);
474                                                 break;
475                                 }
476                         }
477                         break;
478                 case NC_NODE:
479                         if (wmn->action == NA_SELECTED) {
480                                 /* selection changed, so force refresh to flush (needs flag set to do syncing) */
481                                 saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
482                                 ED_area_tag_refresh(sa);
483                         }
484                         break;
485                 case NC_SPACE:
486                         switch (wmn->data) {
487                                 case ND_SPACE_DOPESHEET:
488                                         ED_area_tag_redraw(sa);
489                                         break;
490                                 case ND_SPACE_CHANGED:
491                                         saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
492                                         ED_area_tag_refresh(sa);
493                                         break;
494                         }
495                         break;
496                 case NC_WINDOW:
497                         if (saction->flag & SACTION_TEMP_NEEDCHANSYNC) {
498                                 /* force redraw/refresh after undo/redo - [#28962] */
499                                 ED_area_tag_refresh(sa);
500                         }
501                         break;
502         }
503 }
504
505 static void action_header_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
506 {
507         // SpaceAction *saction = (SpaceAction *)sa->spacedata.first;
508
509         /* context changes */
510         switch (wmn->category) {
511                 case NC_SCENE:
512                         switch (wmn->data) {
513                                 case ND_OB_ACTIVE:
514                                         ED_region_tag_redraw(ar);
515                                         break;
516                         }
517                         break;
518                 case NC_ID:
519                         if (wmn->action == NA_RENAME)
520                                 ED_region_tag_redraw(ar);
521                         break;
522                 case NC_ANIMATION:
523                         switch (wmn->data) {
524                                 case ND_ANIMCHAN: /* set of visible animchannels changed */
525                                         /* NOTE: for now, this should usually just mean that the filters changed 
526                                          *       It may be better if we had a dedicated flag for that though
527                                          */
528                                         ED_region_tag_redraw(ar);
529                                         break;
530                                         
531                                 case ND_KEYFRAME: /* new keyframed added -> active action may have changed */
532                                         //saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
533                                         ED_region_tag_redraw(ar);
534                                         break;
535                         }
536                         break;
537         }
538
539 }
540
541 /* add handlers, stuff you only do once or on area/region changes */
542 static void action_buttons_area_init(wmWindowManager *wm, ARegion *ar)
543 {
544         wmKeyMap *keymap;
545         
546         ED_region_panels_init(wm, ar);
547         
548         keymap = WM_keymap_find(wm->defaultconf, "Dopesheet Generic", SPACE_ACTION, 0);
549         WM_event_add_keymap_handler(&ar->handlers, keymap);
550 }
551
552 static void action_buttons_area_draw(const bContext *C, ARegion *ar)
553 {
554         ED_region_panels(C, ar, NULL, -1, true);
555 }
556
557 static void action_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
558 {
559         /* context changes */
560         switch (wmn->category) {
561                 case NC_ANIMATION:
562                         ED_region_tag_redraw(ar);
563                         break;
564                 case NC_SCENE:
565                         switch (wmn->data) {
566                                 case ND_OB_ACTIVE:
567                                 case ND_FRAME:
568                                 case ND_MARKERS:
569                                         ED_region_tag_redraw(ar);
570                                         break;
571                         }
572                         break;
573                 case NC_OBJECT:
574                         switch (wmn->data) {
575                                 case ND_BONE_ACTIVE:
576                                 case ND_BONE_SELECT:
577                                 case ND_KEYS:
578                                         ED_region_tag_redraw(ar);
579                                         break;
580                         }
581                         break;
582                 default:
583                         if (wmn->data == ND_KEYS)
584                                 ED_region_tag_redraw(ar);
585                         break;
586         }
587 }
588
589 static void action_refresh(const bContext *C, ScrArea *sa)
590 {
591         SpaceAction *saction = (SpaceAction *)sa->spacedata.first;
592         
593         /* update the state of the animchannels in response to changes from the data they represent 
594          * NOTE: the temp flag is used to indicate when this needs to be done, and will be cleared once handled
595          */
596         if (saction->flag & SACTION_TEMP_NEEDCHANSYNC) {
597                 ARegion *ar;
598                 
599                 /* Perform syncing of channel state incl. selection
600                  * Active action setting also occurs here (as part of anim channel filtering in anim_filter.c)
601                  */
602                 ANIM_sync_animchannels_to_data(C);
603                 saction->flag &= ~SACTION_TEMP_NEEDCHANSYNC;
604                 
605                 /* Tag everything for redraw
606                  * - Regions (such as header) need to be manually tagged for redraw too
607                  *   or else they don't update [#28962]
608                  */
609                 ED_area_tag_redraw(sa);
610                 for (ar = sa->regionbase.first; ar; ar = ar->next)
611                         ED_region_tag_redraw(ar);
612         }
613         
614         /* region updates? */
615         // XXX re-sizing y-extents of tot should go here?
616 }
617
618 static void action_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID *new_id)
619 {
620         SpaceAction *sact = (SpaceAction *)slink;
621
622         if (!ELEM(GS(old_id->name), ID_GR)) {
623                 return;
624         }
625
626         if ((ID *)sact->ads.filter_grp == old_id) {
627                 sact->ads.filter_grp = (Group *)new_id;
628         }
629 }
630
631 /* only called once, from space/spacetypes.c */
632 void ED_spacetype_action(void)
633 {
634         SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype action");
635         ARegionType *art;
636         
637         st->spaceid = SPACE_ACTION;
638         strncpy(st->name, "Action", BKE_ST_MAXNAME);
639         
640         st->new = action_new;
641         st->free = action_free;
642         st->init = action_init;
643         st->duplicate = action_duplicate;
644         st->operatortypes = action_operatortypes;
645         st->keymap = action_keymap;
646         st->listener = action_listener;
647         st->refresh = action_refresh;
648         st->id_remap = action_id_remap;
649
650         /* regions: main window */
651         art = MEM_callocN(sizeof(ARegionType), "spacetype action region");
652         art->regionid = RGN_TYPE_WINDOW;
653         art->init = action_main_region_init;
654         art->draw = action_main_region_draw;
655         art->listener = action_main_region_listener;
656         art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_MARKERS | ED_KEYMAP_ANIMATION | ED_KEYMAP_FRAMES;
657
658         BLI_addhead(&st->regiontypes, art);
659         
660         /* regions: header */
661         art = MEM_callocN(sizeof(ARegionType), "spacetype action region");
662         art->regionid = RGN_TYPE_HEADER;
663         art->prefsizey = HEADERY;
664         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER;
665         
666         art->init = action_header_region_init;
667         art->draw = action_header_region_draw;
668         art->listener = action_header_region_listener;
669         
670         BLI_addhead(&st->regiontypes, art);
671         
672         /* regions: channels */
673         art = MEM_callocN(sizeof(ARegionType), "spacetype action region");
674         art->regionid = RGN_TYPE_CHANNELS;
675         art->prefsizex = 200;
676         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES;
677         
678         art->init = action_channel_region_init;
679         art->draw = action_channel_region_draw;
680         art->listener = action_channel_region_listener;
681         
682         BLI_addhead(&st->regiontypes, art);
683         
684         /* regions: UI buttons */
685         art = MEM_callocN(sizeof(ARegionType), "spacetype action region");
686         art->regionid = RGN_TYPE_UI;
687         art->prefsizex = 200;
688         art->keymapflag = ED_KEYMAP_UI;
689         art->listener = action_region_listener;
690         art->init = action_buttons_area_init;
691         art->draw = action_buttons_area_draw;
692         
693         BLI_addhead(&st->regiontypes, art);
694         
695         action_buttons_register(art);
696         
697         BKE_spacetype_register(st);
698 }
699