DNA: add runtime struct to for graph & action editor
[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->runtime.flag |= SACTION_RUNTIME_FLAG_NEED_CHAN_SYNC;
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_ensure(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_ensure(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_ensure(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_ensure(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 (ELEM(wmn->action, NA_RENAME, NA_SELECTED))
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                         /* only handle these events in GPencil mode for performance considerations */
411                         if (saction->mode == SACTCONT_GPENCIL) {
412                                 if (wmn->action == NA_EDITED) {
413                                         ED_area_tag_redraw(sa);
414                                 }
415                                 else if (wmn->action == NA_SELECTED) {
416                                         saction->runtime.flag |= SACTION_RUNTIME_FLAG_NEED_CHAN_SYNC;
417                                         ED_area_tag_refresh(sa);
418                                 }
419                         }
420                         break;
421                 case NC_ANIMATION:
422                         /* for NLA tweakmode enter/exit, need complete refresh */
423                         if (wmn->data == ND_NLA_ACTCHANGE) {
424                                 saction->runtime.flag |= SACTION_RUNTIME_FLAG_NEED_CHAN_SYNC;
425                                 ED_area_tag_refresh(sa);
426                         }
427                         /* autocolor only really needs to change when channels are added/removed, or previously hidden stuff appears
428                          * (assume for now that if just adding these works, that will be fine)
429                          */
430                         else if (((wmn->data == ND_KEYFRAME) && ELEM(wmn->action, NA_ADDED, NA_REMOVED)) ||
431                                  ((wmn->data == ND_ANIMCHAN) && (wmn->action != NA_SELECTED)))
432                         {
433                                 ED_area_tag_refresh(sa);
434                         }
435                         /* for simple edits to the curve data though (or just plain selections), a simple redraw should work
436                          * (see T39851 for an example of how this can go wrong)
437                          */
438                         else {
439                                 ED_area_tag_redraw(sa);
440                         }
441                         break;
442                 case NC_SCENE:
443                         switch (wmn->data) {
444                                 case ND_OB_ACTIVE:  /* selection changed, so force refresh to flush (needs flag set to do syncing) */
445                                 case ND_OB_SELECT:
446                                         saction->runtime.flag |= SACTION_RUNTIME_FLAG_NEED_CHAN_SYNC;
447                                         ED_area_tag_refresh(sa);
448                                         break;
449
450                                 default: /* just redrawing the view will do */
451                                         ED_area_tag_redraw(sa);
452                                         break;
453                         }
454                         break;
455                 case NC_OBJECT:
456                         switch (wmn->data) {
457                                 case ND_BONE_SELECT:    /* selection changed, so force refresh to flush (needs flag set to do syncing) */
458                                 case ND_BONE_ACTIVE:
459                                         saction->runtime.flag |= SACTION_RUNTIME_FLAG_NEED_CHAN_SYNC;
460                                         ED_area_tag_refresh(sa);
461                                         break;
462                                 case ND_TRANSFORM:
463                                         /* moving object shouldn't need to redraw action */
464                                         break;
465                                 default: /* just redrawing the view will do */
466                                         ED_area_tag_redraw(sa);
467                                         break;
468                         }
469                         break;
470                 case NC_MASK:
471                         if (saction->mode == SACTCONT_MASK) {
472                                 switch (wmn->data) {
473                                         case ND_DATA:
474                                                 ED_area_tag_refresh(sa);
475                                                 ED_area_tag_redraw(sa);
476                                                 break;
477                                         default: /* just redrawing the view will do */
478                                                 ED_area_tag_redraw(sa);
479                                                 break;
480                                 }
481                         }
482                         break;
483                 case NC_NODE:
484                         if (wmn->action == NA_SELECTED) {
485                                 /* selection changed, so force refresh to flush (needs flag set to do syncing) */
486                                 saction->runtime.flag |= SACTION_RUNTIME_FLAG_NEED_CHAN_SYNC;
487                                 ED_area_tag_refresh(sa);
488                         }
489                         break;
490                 case NC_SPACE:
491                         switch (wmn->data) {
492                                 case ND_SPACE_DOPESHEET:
493                                         ED_area_tag_redraw(sa);
494                                         break;
495                                 case ND_SPACE_CHANGED:
496                                         saction->runtime.flag |= SACTION_RUNTIME_FLAG_NEED_CHAN_SYNC;
497                                         ED_area_tag_refresh(sa);
498                                         break;
499                         }
500                         break;
501                 case NC_WINDOW:
502                         if (saction->runtime.flag & SACTION_RUNTIME_FLAG_NEED_CHAN_SYNC) {
503                                 /* force redraw/refresh after undo/redo - [#28962] */
504                                 ED_area_tag_refresh(sa);
505                         }
506                         break;
507         }
508 }
509
510 static void action_header_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
511 {
512         // SpaceAction *saction = (SpaceAction *)sa->spacedata.first;
513
514         /* context changes */
515         switch (wmn->category) {
516                 case NC_SCENE:
517                         switch (wmn->data) {
518                                 case ND_OB_ACTIVE:
519                                         ED_region_tag_redraw(ar);
520                                         break;
521                         }
522                         break;
523                 case NC_ID:
524                         if (wmn->action == NA_RENAME)
525                                 ED_region_tag_redraw(ar);
526                         break;
527                 case NC_ANIMATION:
528                         switch (wmn->data) {
529                                 case ND_ANIMCHAN: /* set of visible animchannels changed */
530                                         /* NOTE: for now, this should usually just mean that the filters changed
531                                          *       It may be better if we had a dedicated flag for that though
532                                          */
533                                         ED_region_tag_redraw(ar);
534                                         break;
535
536                                 case ND_KEYFRAME: /* new keyframed added -> active action may have changed */
537                                         //saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
538                                         ED_region_tag_redraw(ar);
539                                         break;
540                         }
541                         break;
542         }
543
544 }
545
546 /* add handlers, stuff you only do once or on area/region changes */
547 static void action_buttons_area_init(wmWindowManager *wm, ARegion *ar)
548 {
549         wmKeyMap *keymap;
550
551         ED_region_panels_init(wm, ar);
552
553         keymap = WM_keymap_ensure(wm->defaultconf, "Dopesheet Generic", SPACE_ACTION, 0);
554         WM_event_add_keymap_handler(&ar->handlers, keymap);
555 }
556
557 static void action_buttons_area_draw(const bContext *C, ARegion *ar)
558 {
559         ED_region_panels(C, ar, NULL, -1, true);
560 }
561
562 static void action_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
563 {
564         /* context changes */
565         switch (wmn->category) {
566                 case NC_ANIMATION:
567                         ED_region_tag_redraw(ar);
568                         break;
569                 case NC_SCENE:
570                         switch (wmn->data) {
571                                 case ND_OB_ACTIVE:
572                                 case ND_FRAME:
573                                 case ND_MARKERS:
574                                         ED_region_tag_redraw(ar);
575                                         break;
576                         }
577                         break;
578                 case NC_OBJECT:
579                         switch (wmn->data) {
580                                 case ND_BONE_ACTIVE:
581                                 case ND_BONE_SELECT:
582                                 case ND_KEYS:
583                                         ED_region_tag_redraw(ar);
584                                         break;
585                         }
586                         break;
587                 default:
588                         if (wmn->data == ND_KEYS)
589                                 ED_region_tag_redraw(ar);
590                         break;
591         }
592 }
593
594 static void action_refresh(const bContext *C, ScrArea *sa)
595 {
596         SpaceAction *saction = (SpaceAction *)sa->spacedata.first;
597
598         /* update the state of the animchannels in response to changes from the data they represent
599          * NOTE: the temp flag is used to indicate when this needs to be done, and will be cleared once handled
600          */
601         if (saction->runtime.flag & SACTION_RUNTIME_FLAG_NEED_CHAN_SYNC) {
602                 ARegion *ar;
603
604                 /* Perform syncing of channel state incl. selection
605                  * Active action setting also occurs here (as part of anim channel filtering in anim_filter.c)
606                  */
607                 ANIM_sync_animchannels_to_data(C);
608                 saction->runtime.flag &= ~SACTION_RUNTIME_FLAG_NEED_CHAN_SYNC;
609
610                 /* Tag everything for redraw
611                  * - Regions (such as header) need to be manually tagged for redraw too
612                  *   or else they don't update [#28962]
613                  */
614                 ED_area_tag_redraw(sa);
615                 for (ar = sa->regionbase.first; ar; ar = ar->next)
616                         ED_region_tag_redraw(ar);
617         }
618
619         /* region updates? */
620         // XXX re-sizing y-extents of tot should go here?
621 }
622
623 static void action_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID *new_id)
624 {
625         SpaceAction *sact = (SpaceAction *)slink;
626
627         if ((ID *)sact->action == old_id) {
628                 sact->action = (bAction *)new_id;
629         }
630
631         if ((ID *)sact->ads.filter_grp == old_id) {
632                 sact->ads.filter_grp = (Group *)new_id;
633         }
634         if ((ID *)sact->ads.source == old_id) {
635                 sact->ads.source = new_id;
636         }
637
638 }
639
640 /* only called once, from space/spacetypes.c */
641 void ED_spacetype_action(void)
642 {
643         SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype action");
644         ARegionType *art;
645
646         st->spaceid = SPACE_ACTION;
647         strncpy(st->name, "Action", BKE_ST_MAXNAME);
648
649         st->new = action_new;
650         st->free = action_free;
651         st->init = action_init;
652         st->duplicate = action_duplicate;
653         st->operatortypes = action_operatortypes;
654         st->keymap = action_keymap;
655         st->listener = action_listener;
656         st->refresh = action_refresh;
657         st->id_remap = action_id_remap;
658
659         /* regions: main window */
660         art = MEM_callocN(sizeof(ARegionType), "spacetype action region");
661         art->regionid = RGN_TYPE_WINDOW;
662         art->init = action_main_region_init;
663         art->draw = action_main_region_draw;
664         art->listener = action_main_region_listener;
665         art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_MARKERS | ED_KEYMAP_ANIMATION | ED_KEYMAP_FRAMES;
666
667         BLI_addhead(&st->regiontypes, art);
668
669         /* regions: header */
670         art = MEM_callocN(sizeof(ARegionType), "spacetype action region");
671         art->regionid = RGN_TYPE_HEADER;
672         art->prefsizey = HEADERY;
673         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER;
674
675         art->init = action_header_region_init;
676         art->draw = action_header_region_draw;
677         art->listener = action_header_region_listener;
678
679         BLI_addhead(&st->regiontypes, art);
680
681         /* regions: channels */
682         art = MEM_callocN(sizeof(ARegionType), "spacetype action region");
683         art->regionid = RGN_TYPE_CHANNELS;
684         art->prefsizex = 200;
685         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES;
686
687         art->init = action_channel_region_init;
688         art->draw = action_channel_region_draw;
689         art->listener = action_channel_region_listener;
690
691         BLI_addhead(&st->regiontypes, art);
692
693         /* regions: UI buttons */
694         art = MEM_callocN(sizeof(ARegionType), "spacetype action region");
695         art->regionid = RGN_TYPE_UI;
696         art->prefsizex = 200;
697         art->keymapflag = ED_KEYMAP_UI;
698         art->listener = action_region_listener;
699         art->init = action_buttons_area_init;
700         art->draw = action_buttons_area_draw;
701
702         BLI_addhead(&st->regiontypes, art);
703
704         action_buttons_register(art);
705
706         BKE_spacetype_register(st);
707 }