Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / space_sequencer / space_sequencer.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_sequencer/space_sequencer.c
28  *  \ingroup spseq
29  */
30
31
32 #include <string.h>
33 #include <stdio.h>
34
35 #include "DNA_gpencil_types.h"
36 #include "DNA_scene_types.h"
37 #include "DNA_mask_types.h"
38
39 #include "MEM_guardedalloc.h"
40
41 #include "BLI_blenlib.h"
42 #include "BLI_utildefines.h"
43
44 #include "BKE_context.h"
45 #include "BKE_library.h"
46 #include "BKE_screen.h"
47 #include "BKE_sequencer.h"
48 #include "BKE_global.h"
49
50 #include "ED_space_api.h"
51 #include "ED_screen.h"
52 #include "ED_view3d.h" /* only for sequencer view3d drawing callback */
53
54 #include "WM_api.h"
55 #include "WM_types.h"
56
57 #include "UI_interface.h"
58 #include "UI_resources.h"
59 #include "UI_view2d.h"
60
61 #include "IMB_imbuf.h"
62
63 #include "sequencer_intern.h"   // own include
64
65 /**************************** common state *****************************/
66
67 static void sequencer_scopes_tag_refresh(ScrArea *sa)
68 {
69         SpaceSeq *sseq = (SpaceSeq *)sa->spacedata.first;
70
71         sseq->scopes.reference_ibuf = NULL;
72 }
73
74 /* ******************** manage regions ********************* */
75
76 ARegion *sequencer_has_buttons_region(ScrArea *sa)
77 {
78         ARegion *ar, *arnew;
79
80         ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
81         if (ar) return ar;
82         
83         /* add subdiv level; after header */
84         ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
85
86         /* is error! */
87         if (ar == NULL) return NULL;
88         
89         arnew = MEM_callocN(sizeof(ARegion), "buttons for sequencer");
90         
91         BLI_insertlinkafter(&sa->regionbase, ar, arnew);
92         arnew->regiontype = RGN_TYPE_UI;
93         arnew->alignment = RGN_ALIGN_RIGHT;
94         
95         arnew->flag = RGN_FLAG_HIDDEN;
96         
97         return arnew;
98 }
99
100 static ARegion *sequencer_find_region(ScrArea *sa, short type)
101 {
102         ARegion *ar = NULL;
103         
104         for (ar = sa->regionbase.first; ar; ar = ar->next)
105                 if (ar->regiontype == type)
106                         return ar;
107
108         return ar;
109 }
110
111 /* ******************** default callbacks for sequencer space ***************** */
112
113 static SpaceLink *sequencer_new(const bContext *C)
114 {
115         Scene *scene = CTX_data_scene(C);
116         ARegion *ar;
117         SpaceSeq *sseq;
118         
119         sseq = MEM_callocN(sizeof(SpaceSeq), "initsequencer");
120         sseq->spacetype = SPACE_SEQ;
121         sseq->chanshown = 0;
122         sseq->view = SEQ_VIEW_SEQUENCE;
123         sseq->mainb = SEQ_DRAW_IMG_IMBUF;
124         sseq->flag = SEQ_SHOW_GPENCIL | SEQ_USE_ALPHA;
125
126         /* header */
127         ar = MEM_callocN(sizeof(ARegion), "header for sequencer");
128         
129         BLI_addtail(&sseq->regionbase, ar);
130         ar->regiontype = RGN_TYPE_HEADER;
131         ar->alignment = RGN_ALIGN_BOTTOM;
132         
133         /* buttons/list view */
134         ar = MEM_callocN(sizeof(ARegion), "buttons for sequencer");
135         
136         BLI_addtail(&sseq->regionbase, ar);
137         ar->regiontype = RGN_TYPE_UI;
138         ar->alignment = RGN_ALIGN_RIGHT;
139         ar->flag = RGN_FLAG_HIDDEN;
140         
141         /* preview region */
142         /* NOTE: if you change values here, also change them in sequencer_init_preview_region */
143         ar = MEM_callocN(sizeof(ARegion), "preview region for sequencer");
144         BLI_addtail(&sseq->regionbase, ar);
145         ar->regiontype = RGN_TYPE_PREVIEW;
146         ar->alignment = RGN_ALIGN_TOP;
147         ar->flag |= RGN_FLAG_HIDDEN;
148         /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */
149         ar->v2d.keepzoom = V2D_KEEPASPECT | V2D_KEEPZOOM | V2D_LIMITZOOM;
150         ar->v2d.minzoom = 0.001f;
151         ar->v2d.maxzoom = 1000.0f;
152         ar->v2d.tot.xmin = -960.0f; /* 1920 width centered */
153         ar->v2d.tot.ymin = -540.0f; /* 1080 height centered */
154         ar->v2d.tot.xmax = 960.0f;
155         ar->v2d.tot.ymax = 540.0f;
156         ar->v2d.min[0] = 0.0f;
157         ar->v2d.min[1] = 0.0f;
158         ar->v2d.max[0] = 12000.0f;
159         ar->v2d.max[1] = 12000.0f;
160         ar->v2d.cur = ar->v2d.tot;
161         ar->v2d.align = V2D_ALIGN_FREE;
162         ar->v2d.keeptot = V2D_KEEPTOT_FREE;
163
164
165         /* main region */
166         ar = MEM_callocN(sizeof(ARegion), "main region for sequencer");
167         
168         BLI_addtail(&sseq->regionbase, ar);
169         ar->regiontype = RGN_TYPE_WINDOW;
170         
171         
172         /* seq space goes from (0,8) to (0, efra) */
173         
174         ar->v2d.tot.xmin = 0.0f;
175         ar->v2d.tot.ymin = 0.0f;
176         ar->v2d.tot.xmax = scene->r.efra;
177         ar->v2d.tot.ymax = 8.0f;
178         
179         ar->v2d.cur = ar->v2d.tot;
180         
181         ar->v2d.min[0] = 10.0f;
182         ar->v2d.min[1] = 0.5f;
183         
184         ar->v2d.max[0] = MAXFRAMEF;
185         ar->v2d.max[1] = MAXSEQ;
186         
187         ar->v2d.minzoom = 0.01f;
188         ar->v2d.maxzoom = 100.0f;
189
190         ar->v2d.scroll |= (V2D_SCROLL_BOTTOM | V2D_SCROLL_SCALE_HORIZONTAL);
191         ar->v2d.scroll |= (V2D_SCROLL_LEFT | V2D_SCROLL_SCALE_VERTICAL);
192         ar->v2d.keepzoom = 0;
193         ar->v2d.keeptot = 0;
194         ar->v2d.align = V2D_ALIGN_NO_NEG_Y;
195
196         return (SpaceLink *)sseq;
197 }
198
199 /* not spacelink itself */
200 static void sequencer_free(SpaceLink *sl)
201 {       
202         SpaceSeq *sseq = (SpaceSeq *) sl;
203         SequencerScopes *scopes = &sseq->scopes;
204
205 // XXX  if (sseq->gpd) BKE_gpencil_free(sseq->gpd);
206
207         if (scopes->zebra_ibuf)
208                 IMB_freeImBuf(scopes->zebra_ibuf);
209
210         if (scopes->waveform_ibuf)
211                 IMB_freeImBuf(scopes->waveform_ibuf);
212
213         if (scopes->sep_waveform_ibuf)
214                 IMB_freeImBuf(scopes->sep_waveform_ibuf);
215
216         if (scopes->vector_ibuf)
217                 IMB_freeImBuf(scopes->vector_ibuf);
218
219         if (scopes->histogram_ibuf)
220                 IMB_freeImBuf(scopes->histogram_ibuf);
221 }
222
223
224 /* spacetype; init callback */
225 static void sequencer_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
226 {
227         
228 }
229
230 static void sequencer_refresh(const bContext *C, ScrArea *sa)
231 {
232         wmWindowManager *wm = CTX_wm_manager(C);
233         wmWindow *window = CTX_wm_window(C);
234         SpaceSeq *sseq = (SpaceSeq *)sa->spacedata.first;
235         ARegion *ar_main = sequencer_find_region(sa, RGN_TYPE_WINDOW);
236         ARegion *ar_preview = sequencer_find_region(sa, RGN_TYPE_PREVIEW);
237         bool view_changed = false;
238
239         switch (sseq->view) {
240                 case SEQ_VIEW_SEQUENCE:
241                         if (ar_main && (ar_main->flag & RGN_FLAG_HIDDEN)) {
242                                 ar_main->flag &= ~RGN_FLAG_HIDDEN;
243                                 ar_main->v2d.flag &= ~V2D_IS_INITIALISED;
244                                 view_changed = true;
245                         }
246                         if (ar_preview && !(ar_preview->flag & RGN_FLAG_HIDDEN)) {
247                                 ar_preview->flag |= RGN_FLAG_HIDDEN;
248                                 ar_preview->v2d.flag &= ~V2D_IS_INITIALISED;
249                                 WM_event_remove_handlers((bContext *)C, &ar_preview->handlers);
250                                 view_changed = true;
251                         }
252                         if (ar_main && ar_main->alignment != RGN_ALIGN_NONE) {
253                                 ar_main->alignment = RGN_ALIGN_NONE;
254                                 view_changed = true;
255                         }
256                         if (ar_preview && ar_preview->alignment != RGN_ALIGN_NONE) {
257                                 ar_preview->alignment = RGN_ALIGN_NONE;
258                                 view_changed = true;
259                         }
260                         break;
261                 case SEQ_VIEW_PREVIEW:
262                         if (ar_main && !(ar_main->flag & RGN_FLAG_HIDDEN)) {
263                                 ar_main->flag |= RGN_FLAG_HIDDEN;
264                                 ar_main->v2d.flag &= ~V2D_IS_INITIALISED;
265                                 WM_event_remove_handlers((bContext *)C, &ar_main->handlers);
266                                 view_changed = true;
267                         }
268                         if (ar_preview && (ar_preview->flag & RGN_FLAG_HIDDEN)) {
269                                 ar_preview->flag &= ~RGN_FLAG_HIDDEN;
270                                 ar_preview->v2d.flag &= ~V2D_IS_INITIALISED;
271                                 ar_preview->v2d.cur = ar_preview->v2d.tot;
272                                 view_changed = true;
273                         }
274                         if (ar_main && ar_main->alignment != RGN_ALIGN_NONE) {
275                                 ar_main->alignment = RGN_ALIGN_NONE;
276                                 view_changed = true;
277                         }
278                         if (ar_preview && ar_preview->alignment != RGN_ALIGN_NONE) {
279                                 ar_preview->alignment = RGN_ALIGN_NONE;
280                                 view_changed = true;
281                         }
282                         break;
283                 case SEQ_VIEW_SEQUENCE_PREVIEW:
284                         if (ar_main && ar_preview) {
285                                 /* Get available height (without DPI correction). */
286                                 const float height = (sa->winy - ED_area_headersize()) / UI_DPI_FAC;
287
288                                 /* We reuse hidden region's size, allows to find same layout as before if we just switch
289                                  * between one 'full window' view and the combined one. This gets lost if we switch to both
290                                  * 'full window' views before, though... Better than nothing. */
291                                 if (ar_main->flag & RGN_FLAG_HIDDEN) {
292                                         ar_main->flag &= ~RGN_FLAG_HIDDEN;
293                                         ar_main->v2d.flag &= ~V2D_IS_INITIALISED;
294                                         ar_preview->sizey = (int)(height - ar_main->sizey);
295                                         view_changed = true;
296                                 }
297                                 if (ar_preview->flag & RGN_FLAG_HIDDEN) {
298                                         ar_preview->flag &= ~RGN_FLAG_HIDDEN;
299                                         ar_preview->v2d.flag &= ~V2D_IS_INITIALISED;
300                                         ar_preview->v2d.cur = ar_preview->v2d.tot;
301                                         ar_main->sizey = (int)(height - ar_preview->sizey);
302                                         view_changed = true;
303                                 }
304                                 if (ar_main->alignment != RGN_ALIGN_NONE) {
305                                         ar_main->alignment = RGN_ALIGN_NONE;
306                                         view_changed = true;
307                                 }
308                                 if (ar_preview->alignment != RGN_ALIGN_TOP) {
309                                         ar_preview->alignment = RGN_ALIGN_TOP;
310                                         view_changed = true;
311                                 }
312                                 /* Final check that both preview and main height are reasonable! */
313                                 if (ar_preview->sizey < 10 || ar_main->sizey < 10 || ar_preview->sizey + ar_main->sizey > height) {
314                                         ar_preview->sizey = (int)(height * 0.4f + 0.5f);
315                                         ar_main->sizey = (int)(height - ar_preview->sizey);
316                                         view_changed = true;
317                                 }
318                         }
319                         break;
320         }
321
322         if (view_changed) {
323                 ED_area_initialize(wm, window, sa);
324                 ED_area_tag_redraw(sa);
325         }
326 }
327
328 static SpaceLink *sequencer_duplicate(SpaceLink *sl)
329 {
330         SpaceSeq *sseqn = MEM_dupallocN(sl);
331         
332         /* clear or remove stuff from old */
333 // XXX  sseq->gpd = gpencil_data_duplicate(sseq->gpd, false);
334
335         memset(&sseqn->scopes, 0, sizeof(sseqn->scopes));
336
337         return (SpaceLink *)sseqn;
338 }
339
340 static void sequencer_listener(
341         bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn, const Scene *UNUSED(scene))
342 {
343         /* context changes */
344         switch (wmn->category) {
345                 case NC_SCENE:
346                         switch (wmn->data) {
347                                 case ND_FRAME:
348                                 case ND_SEQUENCER:
349                                         sequencer_scopes_tag_refresh(sa);
350                                         break;
351                         }
352                         break;
353                 case NC_WINDOW:
354                 case NC_SPACE:
355                         if (wmn->data == ND_SPACE_SEQUENCER)
356                                 sequencer_scopes_tag_refresh(sa);
357                         break;
358                 case NC_GPENCIL:
359                         if (wmn->data & ND_GPENCIL_EDITMODE)
360                                 ED_area_tag_redraw(sa);
361                         break;
362         }
363 }
364
365 /* ************* dropboxes ************* */
366
367 static int image_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
368 {
369         ARegion *ar = CTX_wm_region(C);
370         Scene *scene = CTX_data_scene(C);
371         int hand;
372
373         if (drag->type == WM_DRAG_PATH)
374                 if (ELEM(drag->icon, ICON_FILE_IMAGE, ICON_FILE_BLANK)) /* rule might not work? */
375                         if (find_nearest_seq(scene, &ar->v2d, &hand, event->mval) == NULL)
376                                 return 1;
377
378         return 0;
379 }
380
381 static int movie_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
382 {
383         ARegion *ar = CTX_wm_region(C);
384         Scene *scene = CTX_data_scene(C);
385         int hand;
386
387         if (drag->type == WM_DRAG_PATH)
388                 if (ELEM(drag->icon, 0, ICON_FILE_MOVIE, ICON_FILE_BLANK)) /* rule might not work? */
389                         if (find_nearest_seq(scene, &ar->v2d, &hand, event->mval) == NULL)
390                                 return 1;
391         return 0;
392 }
393
394 static int sound_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
395 {
396         ARegion *ar = CTX_wm_region(C);
397         Scene *scene = CTX_data_scene(C);
398         int hand;
399
400         if (drag->type == WM_DRAG_PATH)
401                 if (ELEM(drag->icon, ICON_FILE_SOUND, ICON_FILE_BLANK)) /* rule might not work? */
402                         if (find_nearest_seq(scene, &ar->v2d, &hand, event->mval) == NULL)
403                                 return 1;
404         return 0;
405 }
406
407 static void sequencer_drop_copy(wmDrag *drag, wmDropBox *drop)
408 {
409         /* copy drag path to properties */
410         if (RNA_struct_find_property(drop->ptr, "filepath"))
411                 RNA_string_set(drop->ptr, "filepath", drag->path);
412
413         if (RNA_struct_find_property(drop->ptr, "directory")) {
414                 PointerRNA itemptr;
415                 char dir[FILE_MAX], file[FILE_MAX];
416
417                 BLI_split_dirfile(drag->path, dir, file, sizeof(dir), sizeof(file));
418                 
419                 RNA_string_set(drop->ptr, "directory", dir);
420
421                 RNA_collection_clear(drop->ptr, "files");
422                 RNA_collection_add(drop->ptr, "files", &itemptr);
423                 RNA_string_set(&itemptr, "name", file);
424         }
425 }
426
427 /* this region dropbox definition */
428 static void sequencer_dropboxes(void)
429 {
430         ListBase *lb = WM_dropboxmap_find("Sequencer", SPACE_SEQ, RGN_TYPE_WINDOW);
431
432         WM_dropbox_add(lb, "SEQUENCER_OT_image_strip_add", image_drop_poll, sequencer_drop_copy);
433         WM_dropbox_add(lb, "SEQUENCER_OT_movie_strip_add", movie_drop_poll, sequencer_drop_copy);
434         WM_dropbox_add(lb, "SEQUENCER_OT_sound_strip_add", sound_drop_poll, sequencer_drop_copy);
435 }
436
437 /* ************* end drop *********** */
438
439 /* DO NOT make this static, this hides the symbol and breaks API generation script. */
440 const char *sequencer_context_dir[] = {"edit_mask", NULL};
441
442 static int sequencer_context(const bContext *C, const char *member, bContextDataResult *result)
443 {
444         Scene *scene = CTX_data_scene(C);
445
446         if (CTX_data_dir(member)) {
447                 CTX_data_dir_set(result, sequencer_context_dir);
448
449                 return true;
450         }
451         else if (CTX_data_equals(member, "edit_mask")) {
452                 Mask *mask = BKE_sequencer_mask_get(scene);
453                 if (mask) {
454                         CTX_data_id_pointer_set(result, &mask->id);
455                 }
456                 return true;
457         }
458
459         return false;
460 }
461
462 /* *********************** sequencer (main) region ************************ */
463 /* add handlers, stuff you only do once or on area/region changes */
464 static void sequencer_main_region_init(wmWindowManager *wm, ARegion *ar)
465 {
466         wmKeyMap *keymap;
467         ListBase *lb;
468
469         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
470
471 #if 0
472         keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0);
473         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
474 #endif
475
476         keymap = WM_keymap_find(wm->defaultconf, "SequencerCommon", SPACE_SEQ, 0);
477         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
478
479         /* own keymap */
480         keymap = WM_keymap_find(wm->defaultconf, "Sequencer", SPACE_SEQ, 0);
481         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
482
483         /* add drop boxes */
484         lb = WM_dropboxmap_find("Sequencer", SPACE_SEQ, RGN_TYPE_WINDOW);
485
486         WM_event_add_dropbox_handler(&ar->handlers, lb);
487 }
488
489 static void sequencer_main_region_draw(const bContext *C, ARegion *ar)
490 {
491         /* NLE - strip editing timeline interface */
492         draw_timeline_seq(C, ar);
493 }
494
495 static void sequencer_main_region_listener(
496         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
497         wmNotifier *wmn, const Scene *UNUSED(scene))
498 {
499         /* context changes */
500         switch (wmn->category) {
501                 case NC_SCENE:
502                         switch (wmn->data) {
503                                 case ND_FRAME:
504                                 case ND_FRAME_RANGE:
505                                 case ND_MARKERS:
506                                 case ND_RENDER_OPTIONS: /* for FPS and FPS Base */
507                                 case ND_SEQUENCER:
508                                 case ND_RENDER_RESULT:
509                                         ED_region_tag_redraw(ar);
510                                         break;
511                         }
512                         break;
513                 case NC_ANIMATION:
514                         switch (wmn->data) {
515                                 case ND_KEYFRAME:
516                                         ED_region_tag_redraw(ar);
517                                         break;
518                         }
519                         break;
520                 case NC_SPACE:
521                         if (wmn->data == ND_SPACE_SEQUENCER)
522                                 ED_region_tag_redraw(ar);
523                         break;
524                 case NC_ID:
525                         if (wmn->action == NA_RENAME)
526                                 ED_region_tag_redraw(ar);
527                         break;
528                 case NC_SCREEN:
529                         if (ELEM(wmn->data, ND_SCREENCAST, ND_ANIMPLAY))
530                                 ED_region_tag_redraw(ar);
531                         break;
532         }
533 }
534
535 /* *********************** header region ************************ */
536 /* add handlers, stuff you only do once or on area/region changes */
537 static void sequencer_header_region_init(wmWindowManager *UNUSED(wm), ARegion *ar)
538 {
539         ED_region_header_init(ar);
540 }
541
542 static void sequencer_header_region_draw(const bContext *C, ARegion *ar)
543 {
544         ED_region_header(C, ar);
545 }
546
547 /* *********************** preview region ************************ */
548 static void sequencer_preview_region_init(wmWindowManager *wm, ARegion *ar)
549 {
550         wmKeyMap *keymap;
551
552         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
553
554 #if 0
555         keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0);
556         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
557 #endif
558
559         keymap = WM_keymap_find(wm->defaultconf, "SequencerCommon", SPACE_SEQ, 0);
560         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
561
562         /* own keymap */
563         keymap = WM_keymap_find(wm->defaultconf, "SequencerPreview", SPACE_SEQ, 0);
564         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
565 }
566
567 static void sequencer_preview_region_draw(const bContext *C, ARegion *ar)
568 {
569         ScrArea *sa = CTX_wm_area(C);
570         SpaceSeq *sseq = sa->spacedata.first;
571         Scene *scene = CTX_data_scene(C);
572         wmWindowManager *wm = CTX_wm_manager(C);
573         const bool show_split = (
574                 scene->ed &&
575                 (scene->ed->over_flag & SEQ_EDIT_OVERLAY_SHOW) &&
576                 (sseq->mainb == SEQ_DRAW_IMG_IMBUF));
577
578         /* XXX temp fix for wrong setting in sseq->mainb */
579         if (sseq->mainb == SEQ_DRAW_SEQUENCE) sseq->mainb = SEQ_DRAW_IMG_IMBUF;
580
581         if (!show_split || sseq->overlay_type != SEQ_DRAW_OVERLAY_REFERENCE)
582                 draw_image_seq(C, scene, ar, sseq, scene->r.cfra, 0, false, false);
583
584         if (show_split && sseq->overlay_type != SEQ_DRAW_OVERLAY_CURRENT) {
585                 int over_cfra;
586
587                 if (scene->ed->over_flag & SEQ_EDIT_OVERLAY_ABS)
588                         over_cfra = scene->ed->over_cfra;
589                 else
590                         over_cfra = scene->r.cfra + scene->ed->over_ofs;
591
592                 if (over_cfra != scene->r.cfra || sseq->overlay_type != SEQ_DRAW_OVERLAY_RECT)
593                         draw_image_seq(C, scene, ar, sseq, scene->r.cfra, over_cfra - scene->r.cfra, true, false);
594         }
595
596         if ((U.uiflag & USER_SHOW_FPS) && ED_screen_animation_no_scrub(wm)) {
597                 rcti rect;
598                 ED_region_visible_rect(ar, &rect);
599                 ED_scene_draw_fps(scene, &rect);
600         }
601 }
602
603 static void sequencer_preview_region_listener(
604         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
605         wmNotifier *wmn, const Scene *UNUSED(scene))
606 {
607         /* context changes */
608         switch (wmn->category) {
609                 case NC_GPENCIL:
610                         if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) {
611                                 ED_region_tag_redraw(ar);
612                         }
613                         break;
614                 case NC_SCENE:
615                         switch (wmn->data) {
616                                 case ND_FRAME:
617                                 case ND_MARKERS:
618                                 case ND_SEQUENCER:
619                                 case ND_RENDER_OPTIONS:
620                                 case ND_DRAW_RENDER_VIEWPORT:
621                                         ED_region_tag_redraw(ar);
622                                         break;
623                         }
624                         break;
625                 case NC_ANIMATION:
626                         switch (wmn->data) {
627                                 case ND_KEYFRAME:
628                                         /* Otherwise, often prevents seing immediately effects of keyframe editing... */
629                                         BKE_sequencer_cache_cleanup();
630                                         ED_region_tag_redraw(ar);
631                                         break;
632                         }
633                         break;
634                 case NC_SPACE:
635                         if (wmn->data == ND_SPACE_SEQUENCER)
636                                 ED_region_tag_redraw(ar);
637                         break;
638                 case NC_ID:
639                         switch (wmn->data) {
640                                 case NA_RENAME:
641                                         ED_region_tag_redraw(ar);
642                                         break;
643                         }
644                         break;
645                 case NC_MASK:
646                         if (wmn->action == NA_EDITED) {
647                                 ED_region_tag_redraw(ar);
648                         }
649                         break;
650         }
651 }
652
653 /* *********************** buttons region ************************ */
654
655 /* add handlers, stuff you only do once or on area/region changes */
656 static void sequencer_buttons_region_init(wmWindowManager *wm, ARegion *ar)
657 {
658         wmKeyMap *keymap;
659
660         keymap = WM_keymap_find(wm->defaultconf, "SequencerCommon", SPACE_SEQ, 0);
661         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
662
663         ED_region_panels_init(wm, ar);
664 }
665
666 static void sequencer_buttons_region_draw(const bContext *C, ARegion *ar)
667 {
668         ED_region_panels(C, ar, NULL, -1, true);
669 }
670
671 static void sequencer_buttons_region_listener(
672         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
673         wmNotifier *wmn, const Scene *UNUSED(scene))
674 {
675         /* context changes */
676         switch (wmn->category) {
677                 case NC_GPENCIL:
678                         if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) {
679                                 ED_region_tag_redraw(ar);
680                         }
681                         break;
682                 case NC_SCENE:
683                         switch (wmn->data) {
684                                 case ND_FRAME:
685                                 case ND_SEQUENCER:
686                                         ED_region_tag_redraw(ar);
687                                         break;
688                         }
689                         break;
690                 case NC_SPACE:
691                         if (wmn->data == ND_SPACE_SEQUENCER)
692                                 ED_region_tag_redraw(ar);
693                         break;
694                 case NC_ID:
695                         if (wmn->action == NA_RENAME)
696                                 ED_region_tag_redraw(ar);
697                         break;
698         }
699 }
700
701 static void sequencer_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID *new_id)
702 {
703         SpaceSeq *sseq = (SpaceSeq *)slink;
704
705         if (!ELEM(GS(old_id->name), ID_GD)) {
706                 return;
707         }
708
709         if ((ID *)sseq->gpd == old_id) {
710                 sseq->gpd = (bGPdata *)new_id;
711                 id_us_min(old_id);
712                 id_us_plus(new_id);
713         }
714 }
715
716 /* ************************************* */
717
718 /* only called once, from space/spacetypes.c */
719 void ED_spacetype_sequencer(void)
720 {
721         SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype sequencer");
722         ARegionType *art;
723
724         st->spaceid = SPACE_SEQ;
725         strncpy(st->name, "Sequencer", BKE_ST_MAXNAME);
726
727         st->new = sequencer_new;
728         st->free = sequencer_free;
729         st->init = sequencer_init;
730         st->duplicate = sequencer_duplicate;
731         st->operatortypes = sequencer_operatortypes;
732         st->keymap = sequencer_keymap;
733         st->context = sequencer_context;
734         st->dropboxes = sequencer_dropboxes;
735         st->refresh = sequencer_refresh;
736         st->listener = sequencer_listener;
737         st->id_remap = sequencer_id_remap;
738
739         /* regions: main window */
740         art = MEM_callocN(sizeof(ARegionType), "spacetype sequencer region");
741         art->regionid = RGN_TYPE_WINDOW;
742         art->init = sequencer_main_region_init;
743         art->draw = sequencer_main_region_draw;
744         art->listener = sequencer_main_region_listener;
745         art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_MARKERS | ED_KEYMAP_FRAMES | ED_KEYMAP_ANIMATION;
746
747         BLI_addhead(&st->regiontypes, art);
748
749         /* preview */
750         art = MEM_callocN(sizeof(ARegionType), "spacetype sequencer region");
751         art->regionid = RGN_TYPE_PREVIEW;
752         art->init = sequencer_preview_region_init;
753         art->draw = sequencer_preview_region_draw;
754         art->listener = sequencer_preview_region_listener;
755         art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_GPENCIL;
756         BLI_addhead(&st->regiontypes, art);
757
758         /* regions: listview/buttons */
759         art = MEM_callocN(sizeof(ARegionType), "spacetype sequencer region");
760         art->regionid = RGN_TYPE_UI;
761         art->prefsizex = 220; // XXX
762         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
763         art->listener = sequencer_buttons_region_listener;
764         art->init = sequencer_buttons_region_init;
765         art->draw = sequencer_buttons_region_draw;
766         BLI_addhead(&st->regiontypes, art);
767
768         sequencer_buttons_register(art);
769
770         /* regions: header */
771         art = MEM_callocN(sizeof(ARegionType), "spacetype sequencer region");
772         art->regionid = RGN_TYPE_HEADER;
773         art->prefsizey = HEADERY;
774         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER;
775
776         art->init = sequencer_header_region_init;
777         art->draw = sequencer_header_region_draw;
778         art->listener = sequencer_main_region_listener;
779
780         BLI_addhead(&st->regiontypes, art);
781
782         BKE_spacetype_register(st);
783
784         /* set the sequencer callback when not in background mode */
785         if (G.background == 0) {
786                 sequencer_view3d_cb = ED_view3d_draw_offscreen_imbuf_simple;
787         }
788 }