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 static const char *sequencer_context_dir[] = {"edit_mask", NULL};
440
441 static int sequencer_context(const bContext *C, const char *member, bContextDataResult *result)
442 {
443         Scene *scene = CTX_data_scene(C);
444
445         if (CTX_data_dir(member)) {
446                 CTX_data_dir_set(result, sequencer_context_dir);
447
448                 return true;
449         }
450         else if (CTX_data_equals(member, "edit_mask")) {
451                 Mask *mask = BKE_sequencer_mask_get(scene);
452                 if (mask) {
453                         CTX_data_id_pointer_set(result, &mask->id);
454                 }
455                 return true;
456         }
457
458         return false;
459 }
460
461 /* *********************** sequencer (main) region ************************ */
462 /* add handlers, stuff you only do once or on area/region changes */
463 static void sequencer_main_region_init(wmWindowManager *wm, ARegion *ar)
464 {
465         wmKeyMap *keymap;
466         ListBase *lb;
467
468         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
469
470 #if 0
471         keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0);
472         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
473 #endif
474
475         keymap = WM_keymap_find(wm->defaultconf, "SequencerCommon", SPACE_SEQ, 0);
476         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
477
478         /* own keymap */
479         keymap = WM_keymap_find(wm->defaultconf, "Sequencer", SPACE_SEQ, 0);
480         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
481
482         /* add drop boxes */
483         lb = WM_dropboxmap_find("Sequencer", SPACE_SEQ, RGN_TYPE_WINDOW);
484
485         WM_event_add_dropbox_handler(&ar->handlers, lb);
486 }
487
488 static void sequencer_main_region_draw(const bContext *C, ARegion *ar)
489 {
490         /* NLE - strip editing timeline interface */
491         draw_timeline_seq(C, ar);
492 }
493
494 static void sequencer_main_region_listener(
495         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
496         wmNotifier *wmn, const Scene *UNUSED(scene))
497 {
498         /* context changes */
499         switch (wmn->category) {
500                 case NC_SCENE:
501                         switch (wmn->data) {
502                                 case ND_FRAME:
503                                 case ND_FRAME_RANGE:
504                                 case ND_MARKERS:
505                                 case ND_RENDER_OPTIONS: /* for FPS and FPS Base */
506                                 case ND_SEQUENCER:
507                                 case ND_RENDER_RESULT:
508                                         ED_region_tag_redraw(ar);
509                                         break;
510                         }
511                         break;
512                 case NC_ANIMATION:
513                         switch (wmn->data) {
514                                 case ND_KEYFRAME:
515                                         ED_region_tag_redraw(ar);
516                                         break;
517                         }
518                         break;
519                 case NC_SPACE:
520                         if (wmn->data == ND_SPACE_SEQUENCER)
521                                 ED_region_tag_redraw(ar);
522                         break;
523                 case NC_ID:
524                         if (wmn->action == NA_RENAME)
525                                 ED_region_tag_redraw(ar);
526                         break;
527                 case NC_SCREEN:
528                         if (ELEM(wmn->data, ND_SCREENCAST, ND_ANIMPLAY))
529                                 ED_region_tag_redraw(ar);
530                         break;
531         }
532 }
533
534 /* *********************** header region ************************ */
535 /* add handlers, stuff you only do once or on area/region changes */
536 static void sequencer_header_region_init(wmWindowManager *UNUSED(wm), ARegion *ar)
537 {
538         ED_region_header_init(ar);
539 }
540
541 static void sequencer_header_region_draw(const bContext *C, ARegion *ar)
542 {
543         ED_region_header(C, ar);
544 }
545
546 /* *********************** preview region ************************ */
547 static void sequencer_preview_region_init(wmWindowManager *wm, ARegion *ar)
548 {
549         wmKeyMap *keymap;
550
551         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
552
553 #if 0
554         keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0);
555         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
556 #endif
557
558         keymap = WM_keymap_find(wm->defaultconf, "SequencerCommon", SPACE_SEQ, 0);
559         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
560
561         /* own keymap */
562         keymap = WM_keymap_find(wm->defaultconf, "SequencerPreview", SPACE_SEQ, 0);
563         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
564 }
565
566 static void sequencer_preview_region_draw(const bContext *C, ARegion *ar)
567 {
568         ScrArea *sa = CTX_wm_area(C);
569         SpaceSeq *sseq = sa->spacedata.first;
570         Scene *scene = CTX_data_scene(C);
571         wmWindowManager *wm = CTX_wm_manager(C);
572         const bool show_split = (
573                 scene->ed &&
574                 (scene->ed->over_flag & SEQ_EDIT_OVERLAY_SHOW) &&
575                 (sseq->mainb == SEQ_DRAW_IMG_IMBUF));
576
577         /* XXX temp fix for wrong setting in sseq->mainb */
578         if (sseq->mainb == SEQ_DRAW_SEQUENCE) sseq->mainb = SEQ_DRAW_IMG_IMBUF;
579
580         if (!show_split || sseq->overlay_type != SEQ_DRAW_OVERLAY_REFERENCE)
581                 draw_image_seq(C, scene, ar, sseq, scene->r.cfra, 0, false, false);
582
583         if (show_split && sseq->overlay_type != SEQ_DRAW_OVERLAY_CURRENT) {
584                 int over_cfra;
585
586                 if (scene->ed->over_flag & SEQ_EDIT_OVERLAY_ABS)
587                         over_cfra = scene->ed->over_cfra;
588                 else
589                         over_cfra = scene->r.cfra + scene->ed->over_ofs;
590
591                 if (over_cfra != scene->r.cfra || sseq->overlay_type != SEQ_DRAW_OVERLAY_RECT)
592                         draw_image_seq(C, scene, ar, sseq, scene->r.cfra, over_cfra - scene->r.cfra, true, false);
593         }
594
595         if ((U.uiflag & USER_SHOW_FPS) && ED_screen_animation_no_scrub(wm)) {
596                 rcti rect;
597                 ED_region_visible_rect(ar, &rect);
598                 ED_scene_draw_fps(scene, &rect);
599         }
600 }
601
602 static void sequencer_preview_region_listener(
603         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
604         wmNotifier *wmn, const Scene *UNUSED(scene))
605 {
606         /* context changes */
607         switch (wmn->category) {
608                 case NC_GPENCIL:
609                         if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) {
610                                 ED_region_tag_redraw(ar);
611                         }
612                         break;
613                 case NC_SCENE:
614                         switch (wmn->data) {
615                                 case ND_FRAME:
616                                 case ND_MARKERS:
617                                 case ND_SEQUENCER:
618                                 case ND_RENDER_OPTIONS:
619                                 case ND_DRAW_RENDER_VIEWPORT:
620                                         ED_region_tag_redraw(ar);
621                                         break;
622                         }
623                         break;
624                 case NC_ANIMATION:
625                         switch (wmn->data) {
626                                 case ND_KEYFRAME:
627                                         /* Otherwise, often prevents seing immediately effects of keyframe editing... */
628                                         BKE_sequencer_cache_cleanup();
629                                         ED_region_tag_redraw(ar);
630                                         break;
631                         }
632                         break;
633                 case NC_SPACE:
634                         if (wmn->data == ND_SPACE_SEQUENCER)
635                                 ED_region_tag_redraw(ar);
636                         break;
637                 case NC_ID:
638                         switch (wmn->data) {
639                                 case NA_RENAME:
640                                         ED_region_tag_redraw(ar);
641                                         break;
642                         }
643                         break;
644                 case NC_MASK:
645                         if (wmn->action == NA_EDITED) {
646                                 ED_region_tag_redraw(ar);
647                         }
648                         break;
649         }
650 }
651
652 /* *********************** buttons region ************************ */
653
654 /* add handlers, stuff you only do once or on area/region changes */
655 static void sequencer_buttons_region_init(wmWindowManager *wm, ARegion *ar)
656 {
657         wmKeyMap *keymap;
658
659         keymap = WM_keymap_find(wm->defaultconf, "SequencerCommon", SPACE_SEQ, 0);
660         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
661
662         ED_region_panels_init(wm, ar);
663 }
664
665 static void sequencer_buttons_region_draw(const bContext *C, ARegion *ar)
666 {
667         ED_region_panels(C, ar, NULL, -1, true);
668 }
669
670 static void sequencer_buttons_region_listener(
671         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
672         wmNotifier *wmn, const Scene *UNUSED(scene))
673 {
674         /* context changes */
675         switch (wmn->category) {
676                 case NC_GPENCIL:
677                         if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) {
678                                 ED_region_tag_redraw(ar);
679                         }
680                         break;
681                 case NC_SCENE:
682                         switch (wmn->data) {
683                                 case ND_FRAME:
684                                 case ND_SEQUENCER:
685                                         ED_region_tag_redraw(ar);
686                                         break;
687                         }
688                         break;
689                 case NC_SPACE:
690                         if (wmn->data == ND_SPACE_SEQUENCER)
691                                 ED_region_tag_redraw(ar);
692                         break;
693                 case NC_ID:
694                         if (wmn->action == NA_RENAME)
695                                 ED_region_tag_redraw(ar);
696                         break;
697         }
698 }
699
700 static void sequencer_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID *new_id)
701 {
702         SpaceSeq *sseq = (SpaceSeq *)slink;
703
704         if (!ELEM(GS(old_id->name), ID_GD)) {
705                 return;
706         }
707
708         if ((ID *)sseq->gpd == old_id) {
709                 sseq->gpd = (bGPdata *)new_id;
710                 id_us_min(old_id);
711                 id_us_plus(new_id);
712         }
713 }
714
715 /* ************************************* */
716
717 /* only called once, from space/spacetypes.c */
718 void ED_spacetype_sequencer(void)
719 {
720         SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype sequencer");
721         ARegionType *art;
722
723         st->spaceid = SPACE_SEQ;
724         strncpy(st->name, "Sequencer", BKE_ST_MAXNAME);
725
726         st->new = sequencer_new;
727         st->free = sequencer_free;
728         st->init = sequencer_init;
729         st->duplicate = sequencer_duplicate;
730         st->operatortypes = sequencer_operatortypes;
731         st->keymap = sequencer_keymap;
732         st->context = sequencer_context;
733         st->dropboxes = sequencer_dropboxes;
734         st->refresh = sequencer_refresh;
735         st->listener = sequencer_listener;
736         st->id_remap = sequencer_id_remap;
737
738         /* regions: main window */
739         art = MEM_callocN(sizeof(ARegionType), "spacetype sequencer region");
740         art->regionid = RGN_TYPE_WINDOW;
741         art->init = sequencer_main_region_init;
742         art->draw = sequencer_main_region_draw;
743         art->listener = sequencer_main_region_listener;
744         art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_MARKERS | ED_KEYMAP_FRAMES | ED_KEYMAP_ANIMATION;
745
746         BLI_addhead(&st->regiontypes, art);
747
748         /* preview */
749         art = MEM_callocN(sizeof(ARegionType), "spacetype sequencer region");
750         art->regionid = RGN_TYPE_PREVIEW;
751         art->init = sequencer_preview_region_init;
752         art->draw = sequencer_preview_region_draw;
753         art->listener = sequencer_preview_region_listener;
754         art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_GPENCIL;
755         BLI_addhead(&st->regiontypes, art);
756
757         /* regions: listview/buttons */
758         art = MEM_callocN(sizeof(ARegionType), "spacetype sequencer region");
759         art->regionid = RGN_TYPE_UI;
760         art->prefsizex = 220; // XXX
761         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
762         art->listener = sequencer_buttons_region_listener;
763         art->init = sequencer_buttons_region_init;
764         art->draw = sequencer_buttons_region_draw;
765         BLI_addhead(&st->regiontypes, art);
766
767         sequencer_buttons_register(art);
768
769         /* regions: header */
770         art = MEM_callocN(sizeof(ARegionType), "spacetype sequencer region");
771         art->regionid = RGN_TYPE_HEADER;
772         art->prefsizey = HEADERY;
773         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER;
774
775         art->init = sequencer_header_region_init;
776         art->draw = sequencer_header_region_draw;
777         art->listener = sequencer_main_region_listener;
778
779         BLI_addhead(&st->regiontypes, art);
780
781         BKE_spacetype_register(st);
782
783         /* set the sequencer callback when not in background mode */
784         if (G.background == 0) {
785                 sequencer_view3d_cb = ED_view3d_draw_offscreen_imbuf_simple;
786         }
787 }