iFix T52050: Empty VSE preview for scene strips with OpenGL preview + Rendered settings.
[blender.git] / source / blender / editors / space_sequencer / sequencer_draw.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) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * Contributor(s): Blender Foundation, 2003-2009
22  *
23  * ***** END GPL LICENSE BLOCK *****
24  */
25
26 /** \file blender/editors/space_sequencer/sequencer_draw.c
27  *  \ingroup spseq
28  */
29
30
31 #include <string.h>
32 #include <math.h>
33
34 #include "BLI_blenlib.h"
35 #include "BLI_math.h"
36 #include "BLI_utildefines.h"
37 #include "BLI_threads.h"
38
39 #include "IMB_imbuf_types.h"
40
41 #include "DNA_scene_types.h"
42 #include "DNA_mask_types.h"
43 #include "DNA_object_types.h"
44 #include "DNA_screen_types.h"
45 #include "DNA_space_types.h"
46 #include "DNA_userdef_types.h"
47 #include "DNA_sound_types.h"
48
49 #include "BKE_context.h"
50 #include "BKE_global.h"
51 #include "BKE_main.h"
52 #include "BKE_sequencer.h"
53 #include "BKE_sound.h"
54 #include "BKE_scene.h"
55
56 #include "IMB_colormanagement.h"
57 #include "IMB_imbuf.h"
58
59 #include "BIF_gl.h"
60 #include "BIF_glutil.h"
61
62 #include "GPU_basic_shader.h"
63
64 #include "ED_anim_api.h"
65 #include "ED_gpencil.h"
66 #include "ED_markers.h"
67 #include "ED_mask.h"
68 #include "ED_sequencer.h"
69 #include "ED_screen.h"
70 #include "ED_space_api.h"
71
72 #include "UI_interface.h"
73 #include "UI_resources.h"
74 #include "UI_view2d.h"
75
76 #include "WM_api.h"
77
78 #include "MEM_guardedalloc.h"
79
80 /* own include */
81 #include "sequencer_intern.h"
82
83
84 #define SEQ_LEFTHANDLE   1
85 #define SEQ_RIGHTHANDLE  2
86
87 #define SEQ_HANDLE_SIZE_MIN  7.0f
88 #define SEQ_HANDLE_SIZE_MAX 40.0f
89
90
91 /* Note, Don't use SEQ_BEGIN/SEQ_END while drawing!
92  * it messes up transform, - Campbell */
93 #undef SEQ_BEGIN
94 #undef SEQP_BEGIN
95 #undef SEQ_END
96
97 static Sequence *special_seq_update = NULL;
98
99 void color3ubv_from_seq(Scene *curscene, Sequence *seq, unsigned char col[3])
100 {
101         unsigned char blendcol[3];
102         SolidColorVars *colvars = (SolidColorVars *)seq->effectdata;
103
104         switch (seq->type) {
105                 case SEQ_TYPE_IMAGE:
106                         UI_GetThemeColor3ubv(TH_SEQ_IMAGE, col);
107                         break;
108
109                 case SEQ_TYPE_META:
110                         UI_GetThemeColor3ubv(TH_SEQ_META, col);
111                         break;
112
113                 case SEQ_TYPE_MOVIE:
114                         UI_GetThemeColor3ubv(TH_SEQ_MOVIE, col);
115                         break;
116
117                 case SEQ_TYPE_MOVIECLIP:
118                         UI_GetThemeColor3ubv(TH_SEQ_MOVIECLIP, col);
119                         break;
120
121                 case SEQ_TYPE_MASK:
122                         UI_GetThemeColor3ubv(TH_SEQ_MASK, col); /* TODO */
123                         break;
124
125                 case SEQ_TYPE_SCENE:
126                         UI_GetThemeColor3ubv(TH_SEQ_SCENE, col);
127                 
128                         if (seq->scene == curscene) {
129                                 UI_GetColorPtrShade3ubv(col, col, 20);
130                         }
131                         break;
132                 
133                 /* transitions */
134                 case SEQ_TYPE_CROSS:
135                 case SEQ_TYPE_GAMCROSS:
136                 case SEQ_TYPE_WIPE:
137                         UI_GetThemeColor3ubv(TH_SEQ_TRANSITION, col);
138
139                         /* slightly offset hue to distinguish different effects */
140                         if (seq->type == SEQ_TYPE_CROSS)    rgb_byte_set_hue_float_offset(col, 0.04);
141                         if (seq->type == SEQ_TYPE_GAMCROSS) rgb_byte_set_hue_float_offset(col, 0.08);
142                         if (seq->type == SEQ_TYPE_WIPE)     rgb_byte_set_hue_float_offset(col, 0.12);
143                         break;
144
145                 /* effects */
146                 case SEQ_TYPE_TRANSFORM:
147                 case SEQ_TYPE_SPEED:
148                 case SEQ_TYPE_ADD:
149                 case SEQ_TYPE_SUB:
150                 case SEQ_TYPE_MUL:
151                 case SEQ_TYPE_ALPHAOVER:
152                 case SEQ_TYPE_ALPHAUNDER:
153                 case SEQ_TYPE_OVERDROP:
154                 case SEQ_TYPE_GLOW:
155                 case SEQ_TYPE_MULTICAM:
156                 case SEQ_TYPE_ADJUSTMENT:
157                 case SEQ_TYPE_GAUSSIAN_BLUR:
158                         UI_GetThemeColor3ubv(TH_SEQ_EFFECT, col);
159
160                         /* slightly offset hue to distinguish different effects */
161                         if      (seq->type == SEQ_TYPE_ADD)           rgb_byte_set_hue_float_offset(col, 0.04);
162                         else if (seq->type == SEQ_TYPE_SUB)           rgb_byte_set_hue_float_offset(col, 0.08);
163                         else if (seq->type == SEQ_TYPE_MUL)           rgb_byte_set_hue_float_offset(col, 0.12);
164                         else if (seq->type == SEQ_TYPE_ALPHAOVER)     rgb_byte_set_hue_float_offset(col, 0.16);
165                         else if (seq->type == SEQ_TYPE_ALPHAUNDER)    rgb_byte_set_hue_float_offset(col, 0.20);
166                         else if (seq->type == SEQ_TYPE_OVERDROP)      rgb_byte_set_hue_float_offset(col, 0.24);
167                         else if (seq->type == SEQ_TYPE_GLOW)          rgb_byte_set_hue_float_offset(col, 0.28);
168                         else if (seq->type == SEQ_TYPE_TRANSFORM)     rgb_byte_set_hue_float_offset(col, 0.36);
169                         else if (seq->type == SEQ_TYPE_MULTICAM)      rgb_byte_set_hue_float_offset(col, 0.32);
170                         else if (seq->type == SEQ_TYPE_ADJUSTMENT)    rgb_byte_set_hue_float_offset(col, 0.40);
171                         else if (seq->type == SEQ_TYPE_GAUSSIAN_BLUR) rgb_byte_set_hue_float_offset(col, 0.42);
172                         break;
173
174                 case SEQ_TYPE_COLOR:
175                         rgb_float_to_uchar(col, colvars->col);
176                         break;
177
178                 case SEQ_TYPE_SOUND_RAM:
179                         UI_GetThemeColor3ubv(TH_SEQ_AUDIO, col);
180                         blendcol[0] = blendcol[1] = blendcol[2] = 128;
181                         if (seq->flag & SEQ_MUTE) UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.5, 20);
182                         break;
183
184                 case SEQ_TYPE_TEXT:
185                         UI_GetThemeColor3ubv(TH_SEQ_TEXT, col);
186                         break;
187
188                 default:
189                         col[0] = 10; col[1] = 255; col[2] = 40;
190                         break;
191         }
192 }
193
194 static void drawseqwave(const bContext *C, SpaceSeq *sseq, Scene *scene, Sequence *seq, float x1, float y1, float x2, float y2, float stepsize)
195 {
196         /*
197          * x1 is the starting x value to draw the wave,
198          * x2 the end x value, same for y1 and y2
199          * stepsize is width of a pixel.
200          */
201         if (seq->sound && ((sseq->flag & SEQ_ALL_WAVEFORMS) || (seq->flag & SEQ_AUDIO_DRAW_WAVEFORM))) {
202                 int i, j, pos;
203                 int length = floor((x2 - x1) / stepsize) + 1;
204                 float ymid = (y1 + y2) / 2;
205                 float yscale = (y2 - y1) / 2;
206                 float samplestep;
207                 float startsample, endsample;
208                 float value1, value2;
209                 bSound *sound = seq->sound;
210                 
211                 SoundWaveform *waveform;
212                 
213                 if (!sound->spinlock) {
214                         sound->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock");
215                         BLI_spin_init(sound->spinlock);
216                 }
217                 
218                 BLI_spin_lock(sound->spinlock);
219                 if (!sound->waveform) {
220                         if (!(sound->flags & SOUND_FLAGS_WAVEFORM_LOADING)) {
221                                 /* prevent sounds from reloading */
222                                 sound->flags |= SOUND_FLAGS_WAVEFORM_LOADING;
223                                 BLI_spin_unlock(sound->spinlock);
224                                 sequencer_preview_add_sound(C, seq);
225                         }
226                         else {
227                                 BLI_spin_unlock(sound->spinlock);
228                         }
229                         return;  /* nothing to draw */
230                 }
231                 BLI_spin_unlock(sound->spinlock);
232                 
233                 waveform = sound->waveform;
234
235                 if (waveform->length == 0) {
236                         /* BKE_sound_read_waveform() set an empty SoundWaveform data in case it cannot generate a valid one...
237                          * See T45726. */
238                         return;
239                 }
240
241                 startsample = floor((seq->startofs + seq->anim_startofs) / FPS * SOUND_WAVE_SAMPLES_PER_SECOND);
242                 endsample = ceil((seq->startofs + seq->anim_startofs + seq->enddisp - seq->startdisp) / FPS * SOUND_WAVE_SAMPLES_PER_SECOND);
243                 samplestep = (endsample - startsample) * stepsize / (x2 - x1);
244
245                 if (length > floor((waveform->length - startsample) / samplestep))
246                         length = floor((waveform->length - startsample) / samplestep);
247
248                 glColor4f(1.0f, 1.0f, 1.0f, 0.5);
249                 glEnable(GL_BLEND);
250                 glBegin(GL_TRIANGLE_STRIP);
251                 for (i = 0; i < length; i++) {
252                         float sampleoffset = startsample + i * samplestep;
253                         pos = sampleoffset;
254
255                         value1 = waveform->data[pos * 3];
256                         value2 = waveform->data[pos * 3 + 1];
257
258                         if (samplestep > 1.0f) {
259                                 for (j = pos + 1; (j < waveform->length) && (j < pos + samplestep); j++) {
260                                         if (value1 > waveform->data[j * 3])
261                                                 value1 = waveform->data[j * 3];
262
263                                         if (value2 < waveform->data[j * 3 + 1])
264                                                 value2 = waveform->data[j * 3 + 1];
265                                 }
266                         }
267                         else {
268                                 /* use simple linear interpolation */
269                                 float f = sampleoffset - pos;
270                                 value1 = (1.0f - f) * value1 + f * waveform->data[pos * 3 + 3];
271                                 value2 = (1.0f - f) * value2 + f * waveform->data[pos * 3 + 4];
272                         }
273
274                         glVertex2f(x1 + i * stepsize, ymid + value1 * yscale);
275                         glVertex2f(x1 + i * stepsize, ymid + value2 * yscale);
276                 }
277                 glEnd();
278                 glDisable(GL_BLEND);
279         }
280 }
281
282 static void drawmeta_stipple(int value)
283 {
284         if (value) {
285                 GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
286                 GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_HALFTONE);
287                 
288                 glEnable(GL_LINE_STIPPLE);
289                 glLineStipple(1, 0x8888);
290         }
291         else {
292                 GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
293                 glDisable(GL_LINE_STIPPLE);
294         }
295 }
296
297 static void drawmeta_contents(Scene *scene, Sequence *seqm, float x1, float y1, float x2, float y2)
298 {
299         /* note: this used to use SEQ_BEGIN/SEQ_END, but it messes up the
300          * seq->depth value, (needed by transform when doing overlap checks)
301          * so for now, just use the meta's immediate children, could be fixed but
302          * its only drawing - campbell */
303         Sequence *seq;
304         unsigned char col[4];
305
306         int chan_min = MAXSEQ;
307         int chan_max = 0;
308         int chan_range = 0;
309         float draw_range = y2 - y1;
310         float draw_height;
311         ListBase *seqbase;
312         int offset;
313
314         seqbase = BKE_sequence_seqbase_get(seqm, &offset);
315         if (!seqbase || BLI_listbase_is_empty(seqbase)) {
316                 return;
317         }
318
319         if (seqm->type == SEQ_TYPE_SCENE) {
320                 offset  = seqm->start - offset;
321         }
322         else {
323                 offset = 0;
324         }
325
326         glEnable(GL_BLEND);
327         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
328
329         if (seqm->flag & SEQ_MUTE)
330                 drawmeta_stipple(1);
331
332         for (seq = seqbase->first; seq; seq = seq->next) {
333                 chan_min = min_ii(chan_min, seq->machine);
334                 chan_max = max_ii(chan_max, seq->machine);
335         }
336
337         chan_range = (chan_max - chan_min) + 1;
338         draw_height = draw_range / chan_range;
339
340         col[3] = 196; /* alpha, used for all meta children */
341
342         for (seq = seqbase->first; seq; seq = seq->next) {
343                 const int startdisp = seq->startdisp + offset;
344                 const int enddisp   = seq->enddisp   + offset;
345
346                 if ((startdisp > x2 || enddisp < x1) == 0) {
347                         float y_chan = (seq->machine - chan_min) / (float)(chan_range) * draw_range;
348                         float x1_chan = startdisp;
349                         float x2_chan = enddisp;
350                         float y1_chan, y2_chan;
351
352                         if ((seqm->flag & SEQ_MUTE) == 0 && (seq->flag & SEQ_MUTE))
353                                 drawmeta_stipple(1);
354
355                         color3ubv_from_seq(scene, seq, col);
356
357                         glColor4ubv(col);
358                         
359                         /* clamp within parent sequence strip bounds */
360                         if (x1_chan < x1) x1_chan = x1;
361                         if (x2_chan > x2) x2_chan = x2;
362
363                         y1_chan = y1 + y_chan + (draw_height * SEQ_STRIP_OFSBOTTOM);
364                         y2_chan = y1 + y_chan + (draw_height * SEQ_STRIP_OFSTOP);
365
366                         glRectf(x1_chan,  y1_chan, x2_chan,  y2_chan);
367
368                         UI_GetColorPtrShade3ubv(col, col, -30);
369                         glColor4ubv(col);
370                         fdrawbox(x1_chan,  y1_chan, x2_chan,  y2_chan);
371
372                         if ((seqm->flag & SEQ_MUTE) == 0 && (seq->flag & SEQ_MUTE))
373                                 drawmeta_stipple(0);
374                 }
375         }
376
377         if (seqm->flag & SEQ_MUTE)
378                 drawmeta_stipple(0);
379         
380         glDisable(GL_BLEND);
381 }
382
383 /* clamp handles to defined size in pixel space */
384 static float draw_seq_handle_size_get_clamped(Sequence *seq, const float pixelx)
385 {
386         const float minhandle = pixelx * SEQ_HANDLE_SIZE_MIN;
387         const float maxhandle = pixelx * SEQ_HANDLE_SIZE_MAX;
388         float size = CLAMPIS(seq->handsize, minhandle, maxhandle);
389
390         /* ensure we're not greater than half width */
391         return min_ff(size, ((float)(seq->enddisp - seq->startdisp) / 2.0f) / pixelx);
392 }
393
394 /* draw a handle, for each end of a sequence strip */
395 static void draw_seq_handle(View2D *v2d, Sequence *seq, const float handsize_clamped, const short direction)
396 {
397         float v1[2], v2[2], v3[2], rx1 = 0, rx2 = 0; //for triangles and rect
398         float x1, x2, y1, y2;
399         unsigned int whichsel = 0;
400         
401         x1 = seq->startdisp;
402         x2 = seq->enddisp;
403         
404         y1 = seq->machine + SEQ_STRIP_OFSBOTTOM;
405         y2 = seq->machine + SEQ_STRIP_OFSTOP;
406
407         /* set up co-ordinates/dimensions for either left or right handle */
408         if (direction == SEQ_LEFTHANDLE) {
409                 rx1 = x1;
410                 rx2 = x1 + handsize_clamped * 0.75f;
411                 
412                 v1[0] = x1 + handsize_clamped / 4; v1[1] = y1 + ( ((y1 + y2) / 2.0f - y1) / 2);
413                 v2[0] = x1 + handsize_clamped / 4; v2[1] = y2 - ( ((y1 + y2) / 2.0f - y1) / 2);
414                 v3[0] = v2[0] + handsize_clamped / 4; v3[1] = (y1 + y2) / 2.0f;
415                 
416                 whichsel = SEQ_LEFTSEL;
417         }
418         else if (direction == SEQ_RIGHTHANDLE) {
419                 rx1 = x2 - handsize_clamped * 0.75f;
420                 rx2 = x2;
421                 
422                 v1[0] = x2 - handsize_clamped / 4; v1[1] = y1 + ( ((y1 + y2) / 2.0f - y1) / 2);
423                 v2[0] = x2 - handsize_clamped / 4; v2[1] = y2 - ( ((y1 + y2) / 2.0f - y1) / 2);
424                 v3[0] = v2[0] - handsize_clamped / 4; v3[1] = (y1 + y2) / 2.0f;
425                 
426                 whichsel = SEQ_RIGHTSEL;
427         }
428         
429         /* draw! */
430         if (!(seq->type & SEQ_TYPE_EFFECT) ||
431             BKE_sequence_effect_get_num_inputs(seq->type) == 0)
432         {
433                 glEnable(GL_BLEND);
434                 
435                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
436                 
437                 if (seq->flag & whichsel) glColor4ub(0, 0, 0, 80);
438                 else if (seq->flag & SELECT) glColor4ub(255, 255, 255, 30);
439                 else glColor4ub(0, 0, 0, 22);
440                 
441                 glRectf(rx1, y1, rx2, y2);
442                 
443                 if (seq->flag & whichsel) glColor4ub(255, 255, 255, 200);
444                 else glColor4ub(0, 0, 0, 50);
445                 
446                 glEnable(GL_POLYGON_SMOOTH);
447                 glBegin(GL_TRIANGLES);
448                 glVertex2fv(v1); glVertex2fv(v2); glVertex2fv(v3);
449                 glEnd();
450                 
451                 glDisable(GL_POLYGON_SMOOTH);
452                 glDisable(GL_BLEND);
453         }
454         
455         if ((G.moving & G_TRANSFORM_SEQ) || (seq->flag & whichsel)) {
456                 const char col[4] = {255, 255, 255, 255};
457                 char numstr[32];
458                 size_t numstr_len;
459
460                 if (direction == SEQ_LEFTHANDLE) {
461                         numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), "%d", seq->startdisp);
462                         x1 = rx1;
463                         y1 -= 0.45f;
464                 }
465                 else {
466                         numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), "%d", seq->enddisp - 1);
467                         x1 = x2 - handsize_clamped * 0.75f;
468                         y1 = y2 + 0.05f;
469                 }
470                 UI_view2d_text_cache_add(v2d, x1, y1, numstr, numstr_len, col);
471         }
472 }
473
474 /* draw info text on a sequence strip */
475 static void draw_seq_text(View2D *v2d, SpaceSeq *sseq, Sequence *seq, float x1, float x2, float y1, float y2, const unsigned char background_col[3])
476 {
477         rctf rect;
478         char str[32 + FILE_MAX];
479         size_t str_len;
480         const char *name = seq->name + 2;
481         char col[4];
482
483         /* note, all strings should include 'name' */
484         if (name[0] == '\0')
485                 name = BKE_sequence_give_name(seq);
486
487         if (seq->type == SEQ_TYPE_META || seq->type == SEQ_TYPE_ADJUSTMENT) {
488                 str_len = BLI_snprintf(str, sizeof(str), "%s | %d", name, seq->len);
489         }
490         else if (seq->type == SEQ_TYPE_SCENE) {
491                 if (seq->scene) {
492                         if (seq->scene_camera) {
493                                 str_len = BLI_snprintf(str, sizeof(str), "%s: %s (%s) | %d",
494                                                        name, seq->scene->id.name + 2, ((ID *)seq->scene_camera)->name + 2, seq->len);
495                         }
496                         else {
497                                 str_len = BLI_snprintf(str, sizeof(str), "%s: %s | %d",
498                                                        name, seq->scene->id.name + 2, seq->len);
499                         }
500                 }
501                 else {
502                         str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
503                                                name, seq->len);
504                 }
505         }
506         else if (seq->type == SEQ_TYPE_MOVIECLIP) {
507                 if (seq->clip && !STREQ(name, seq->clip->id.name + 2)) {
508                         str_len = BLI_snprintf(str, sizeof(str), "%s: %s | %d",
509                                                name, seq->clip->id.name + 2, seq->len);
510                 }
511                 else {
512                         str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
513                                                name, seq->len);
514                 }
515         }
516         else if (seq->type == SEQ_TYPE_MASK) {
517                 if (seq->mask && !STREQ(name, seq->mask->id.name + 2)) {
518                         str_len = BLI_snprintf(str, sizeof(str), "%s: %s | %d",
519                                                name, seq->mask->id.name + 2, seq->len);
520                 }
521                 else {
522                         str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
523                                                name, seq->len);
524                 }
525         }
526         else if (seq->type == SEQ_TYPE_MULTICAM) {
527                 str_len = BLI_snprintf(str, sizeof(str), "Cam %s: %d",
528                                        name, seq->multicam_source);
529         }
530         else if (seq->type == SEQ_TYPE_IMAGE) {
531                 str_len = BLI_snprintf(str, sizeof(str), "%s: %s%s | %d",
532                                        name, seq->strip->dir, seq->strip->stripdata->name, seq->len);
533         }
534         else if (seq->type == SEQ_TYPE_TEXT) {
535                 TextVars *textdata = seq->effectdata;
536                 str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
537                                        textdata->text, seq->startdisp);
538         }
539         else if (seq->type & SEQ_TYPE_EFFECT) {
540                 str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
541                                        name, seq->len);
542         }
543         else if (seq->type == SEQ_TYPE_SOUND_RAM) {
544                 /* If a waveform is drawn, we don't want to overlay it with text,
545                  * as it would make both hard to read. */
546                 if ((sseq->flag & SEQ_ALL_WAVEFORMS) || (seq->flag & SEQ_AUDIO_DRAW_WAVEFORM)) {
547                         str[0] = 0;
548                         str_len = 0;
549                 }
550                 else if (seq->sound) {
551                         str_len = BLI_snprintf(str, sizeof(str), "%s: %s | %d",
552                                                name, seq->sound->name, seq->len);
553                 }
554                 else {
555                         str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
556                                                name, seq->len);
557                 }
558         }
559         else if (seq->type == SEQ_TYPE_MOVIE) {
560                 str_len = BLI_snprintf(str, sizeof(str), "%s: %s%s | %d",
561                                        name, seq->strip->dir, seq->strip->stripdata->name, seq->len);
562         }
563         else {
564                 /* should never get here!, but might with files from future */
565                 BLI_assert(0);
566
567                 str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
568                                        name, seq->len);
569         }
570         
571         if (seq->flag & SELECT) {
572                 col[0] = col[1] = col[2] = 255;
573         }
574         else if ((((int)background_col[0] + (int)background_col[1] + (int)background_col[2]) / 3) < 50) {
575                 col[0] = col[1] = col[2] = 80; /* use lighter text color for dark background */
576         }
577         else {
578                 col[0] = col[1] = col[2] = 0;
579         }
580         col[3] = 255;
581
582         rect.xmin = x1;
583         rect.ymin = y1;
584         rect.xmax = x2;
585         rect.ymax = y2;
586
587         UI_view2d_text_cache_add_rectf(v2d, &rect, str, str_len, col);
588 }
589
590 /* draws a shaded strip, made from gradient + flat color + gradient */
591 void draw_shadedstrip(Sequence *seq, unsigned char col[3], float x1, float y1, float x2, float y2)
592 {
593         float ymid1, ymid2;
594         
595         if (seq->flag & SEQ_MUTE) {
596                 GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
597                 GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_HALFTONE);
598         }
599         
600         ymid1 = (y2 - y1) * 0.25f + y1;
601         ymid2 = (y2 - y1) * 0.65f + y1;
602         
603         glBegin(GL_QUADS);
604         
605         if (seq->flag & SEQ_INVALID_EFFECT) { col[0] = 255; col[1] = 0; col[2] = 255; }
606         else if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, -50);
607         /* else UI_GetColorPtrShade3ubv(col, col, 0); */ /* DO NOTHING */
608         
609         glColor3ubv(col);
610         
611         glVertex2f(x1, y1);
612         glVertex2f(x2, y1);
613
614         if (seq->flag & SEQ_INVALID_EFFECT) { col[0] = 255; col[1] = 0; col[2] = 255; }
615         else if (seq->flag & SELECT) UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, 5);
616         else UI_GetColorPtrShade3ubv(col, col, -5);
617
618         glColor3ubv((GLubyte *)col);
619         
620         glVertex2f(x2, ymid1);
621         glVertex2f(x1, ymid1);
622         
623         glEnd();
624         
625         glRectf(x1,  ymid1,  x2,  ymid2);
626         
627         glBegin(GL_QUADS);
628         
629         glVertex2f(x1, ymid2);
630         glVertex2f(x2, ymid2);
631         
632         if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, -15);
633         else UI_GetColorPtrShade3ubv(col, col, 25);
634         
635         glColor3ubv((GLubyte *)col);
636         
637         glVertex2f(x2, y2);
638         glVertex2f(x1, y2);
639         
640         glEnd();
641         
642         if (seq->flag & SEQ_MUTE) {
643                 GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
644         }
645 }
646
647 void draw_sequence_extensions(Scene *scene, ARegion *ar, Sequence *seq)
648 {
649         float x1, x2, y1, y2, pixely, a;
650         unsigned char col[3], blendcol[3];
651         View2D *v2d = &ar->v2d;
652         
653         x1 = seq->startdisp;
654         x2 = seq->enddisp;
655         
656         y1 = seq->machine + SEQ_STRIP_OFSBOTTOM;
657         y2 = seq->machine + SEQ_STRIP_OFSTOP;
658         
659         pixely = BLI_rctf_size_y(&v2d->cur) / BLI_rcti_size_y(&v2d->mask);
660         
661         if (pixely <= 0) return;  /* can happen when the view is split/resized */
662         
663         blendcol[0] = blendcol[1] = blendcol[2] = 120;
664         
665         if (seq->startofs) {
666                 glEnable(GL_BLEND);
667                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
668                 
669                 color3ubv_from_seq(scene, seq, col);
670                 
671                 if (seq->flag & SELECT) {
672                         UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.3, -40);
673                         glColor4ub(col[0], col[1], col[2], 170);
674                 }
675                 else {
676                         UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.6, 0);
677                         glColor4ub(col[0], col[1], col[2], 110);
678                 }
679                 
680                 glRectf((float)(seq->start), y1 - SEQ_STRIP_OFSBOTTOM, x1, y1);
681                 
682                 if (seq->flag & SELECT) glColor4ub(col[0], col[1], col[2], 255);
683                 else glColor4ub(col[0], col[1], col[2], 160);
684                 
685                 fdrawbox((float)(seq->start), y1 - SEQ_STRIP_OFSBOTTOM, x1, y1);  //outline
686                 
687                 glDisable(GL_BLEND);
688         }
689         if (seq->endofs) {
690                 glEnable(GL_BLEND);
691                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
692                 
693                 color3ubv_from_seq(scene, seq, col);
694                 
695                 if (seq->flag & SELECT) {
696                         UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.3, -40);
697                         glColor4ub(col[0], col[1], col[2], 170);
698                 }
699                 else {
700                         UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.6, 0);
701                         glColor4ub(col[0], col[1], col[2], 110);
702                 }
703                 
704                 glRectf(x2, y2, (float)(seq->start + seq->len), y2 + SEQ_STRIP_OFSBOTTOM);
705                 
706                 if (seq->flag & SELECT) glColor4ub(col[0], col[1], col[2], 255);
707                 else glColor4ub(col[0], col[1], col[2], 160);
708                 
709                 fdrawbox(x2, y2, (float)(seq->start + seq->len), y2 + SEQ_STRIP_OFSBOTTOM); //outline
710                 
711                 glDisable(GL_BLEND);
712         }
713         if (seq->startstill) {
714                 color3ubv_from_seq(scene, seq, col);
715                 UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.75, 40);
716                 glColor3ubv((GLubyte *)col);
717                 
718                 draw_shadedstrip(seq, col, x1, y1, (float)(seq->start), y2);
719                 
720                 /* feint pinstripes, helps see exactly which is extended and which isn't,
721                  * especially when the extension is very small */
722                 if (seq->flag & SELECT) UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, 24);
723                 else UI_GetColorPtrShade3ubv(col, col, -16);
724                 
725                 glColor3ubv((GLubyte *)col);
726                 
727                 for (a = y1; a < y2; a += pixely * 2.0f) {
728                         fdrawline(x1,  a,  (float)(seq->start),  a);
729                 }
730         }
731         if (seq->endstill) {
732                 color3ubv_from_seq(scene, seq, col);
733                 UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.75, 40);
734                 glColor3ubv((GLubyte *)col);
735                 
736                 draw_shadedstrip(seq, col, (float)(seq->start + seq->len), y1, x2, y2);
737                 
738                 /* feint pinstripes, helps see exactly which is extended and which isn't,
739                  * especially when the extension is very small */
740                 if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, 24);
741                 else UI_GetColorPtrShade3ubv(col, col, -16);
742                 
743                 glColor3ubv((GLubyte *)col);
744                 
745                 for (a = y1; a < y2; a += pixely * 2.0f) {
746                         fdrawline((float)(seq->start + seq->len),  a,  x2,  a);
747                 }
748         }
749 }
750
751
752 /*
753  * Draw a sequence strip, bounds check already made
754  * ARegion is currently only used to get the windows width in pixels
755  * so wave file sample drawing precision is zoom adjusted
756  */
757 static void draw_seq_strip(const bContext *C, SpaceSeq *sseq, Scene *scene, ARegion *ar, Sequence *seq, int outline_tint, float pixelx)
758 {
759         View2D *v2d = &ar->v2d;
760         float x1, x2, y1, y2;
761         unsigned char col[3], background_col[3], is_single_image;
762         const float handsize_clamped = draw_seq_handle_size_get_clamped(seq, pixelx);
763
764         /* we need to know if this is a single image/color or not for drawing */
765         is_single_image = (char)BKE_sequence_single_check(seq);
766         
767         /* body */
768         x1 = (seq->startstill) ? seq->start : seq->startdisp;
769         y1 = seq->machine + SEQ_STRIP_OFSBOTTOM;
770         x2 = (seq->endstill) ? (seq->start + seq->len) : seq->enddisp;
771         y2 = seq->machine + SEQ_STRIP_OFSTOP;
772
773
774         /* get the correct color per strip type*/
775         //color3ubv_from_seq(scene, seq, col);
776         color3ubv_from_seq(scene, seq, background_col);
777         
778         /* draw the main strip body */
779         if (is_single_image) {  /* single image */
780                 draw_shadedstrip(seq, background_col,
781                                  BKE_sequence_tx_get_final_left(seq, false), y1,
782                                  BKE_sequence_tx_get_final_right(seq, false), y2);
783         }
784         else {  /* normal operation */
785                 draw_shadedstrip(seq, background_col, x1, y1, x2, y2);
786         }
787
788         if (!is_single_image) {
789                 if ((sseq->draw_flag & SEQ_DRAW_OFFSET_EXT) || (seq == special_seq_update)) {
790                         draw_sequence_extensions(scene, ar, seq);
791                 }
792         }
793
794         draw_seq_handle(v2d, seq, handsize_clamped, SEQ_LEFTHANDLE);
795         draw_seq_handle(v2d, seq, handsize_clamped, SEQ_RIGHTHANDLE);
796         
797         /* draw the strip outline */
798         x1 = seq->startdisp;
799         x2 = seq->enddisp;
800         
801         /* draw sound wave */
802         if (seq->type == SEQ_TYPE_SOUND_RAM) {
803                 if (!(sseq->flag & SEQ_NO_WAVEFORMS)) {
804                         drawseqwave(C, sseq, scene, seq, x1, y1, x2, y2, BLI_rctf_size_x(&ar->v2d.cur) / ar->winx);
805                 }
806         }
807
808         /* draw lock */
809         if (seq->flag & SEQ_LOCK) {
810                 GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
811                 glEnable(GL_BLEND);
812
813                 /* light stripes */
814                 glColor4ub(255, 255, 255, 32);
815                 GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_DIAG_STRIPES);
816                 glRectf(x1, y1, x2, y2);
817
818                 /* dark stripes */
819                 glColor4ub(0, 0, 0, 32);
820                 GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_DIAG_STRIPES_SWAP);
821                 glRectf(x1, y1, x2, y2);
822
823                 GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
824                 glDisable(GL_BLEND);
825         }
826
827         if (!BKE_sequence_is_valid_check(seq)) {
828                 GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
829
830                 /* panic! */
831                 glColor4ub(255, 0, 0, 255);
832                 GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_DIAG_STRIPES);
833                 glRectf(x1, y1, x2, y2);
834
835                 GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
836         }
837
838         color3ubv_from_seq(scene, seq, col);
839         if ((G.moving & G_TRANSFORM_SEQ) && (seq->flag & SELECT)) {
840                 if (seq->flag & SEQ_OVERLAP) {
841                         col[0] = 255; col[1] = col[2] = 40;
842                 }
843                 else
844                         UI_GetColorPtrShade3ubv(col, col, 120 + outline_tint);
845         }
846         else
847                 UI_GetColorPtrShade3ubv(col, col, outline_tint);
848         
849         if ((seq->type == SEQ_TYPE_META) ||
850             ((seq->type == SEQ_TYPE_SCENE) && (seq->flag & SEQ_SCENE_STRIPS)))
851         {
852                 drawmeta_contents(scene, seq, x1, y1, x2, y2);
853         }
854
855         if (seq->flag & SEQ_MUTE) {
856                 glEnable(GL_LINE_STIPPLE);
857                 glLineStipple(1, 0x8888);
858         }
859         
860         glColor3ubv((GLubyte *)col);
861         
862         UI_draw_roundbox_shade_x(GL_LINE_LOOP, x1, y1, x2, y2, 0.0, 0.1, 0.0);
863         
864         if (seq->flag & SEQ_MUTE) {
865                 glDisable(GL_LINE_STIPPLE);
866         }
867         
868         /* calculate if seq is long enough to print a name */
869         x1 = seq->startdisp + handsize_clamped;
870         x2 = seq->enddisp   - handsize_clamped;
871
872         /* info text on the strip */
873         if (x1 < v2d->cur.xmin) x1 = v2d->cur.xmin;
874         else if (x1 > v2d->cur.xmax) x1 = v2d->cur.xmax;
875         if (x2 < v2d->cur.xmin) x2 = v2d->cur.xmin;
876         else if (x2 > v2d->cur.xmax) x2 = v2d->cur.xmax;
877
878         /* nice text here would require changing the view matrix for texture text */
879         if ((x2 - x1) / pixelx > 32) {
880                 draw_seq_text(v2d, sseq, seq, x1, x2, y1, y2, background_col);
881         }
882 }
883
884 void sequencer_special_update_set(Sequence *seq)
885 {
886         special_seq_update = seq;
887 }
888
889 Sequence *ED_sequencer_special_preview_get(void)
890 {
891         return special_seq_update;
892 }
893
894 void ED_sequencer_special_preview_set(bContext *C, const int mval[2])
895 {
896         Scene *scene = CTX_data_scene(C);
897         ARegion *ar = CTX_wm_region(C);
898         int hand;
899         Sequence *seq;
900         seq = find_nearest_seq(scene, &ar->v2d, &hand, mval);
901         sequencer_special_update_set(seq);
902 }
903
904 void ED_sequencer_special_preview_clear(void)
905 {
906         sequencer_special_update_set(NULL);
907 }
908
909 ImBuf *sequencer_ibuf_get(struct Main *bmain, Scene *scene, SpaceSeq *sseq, int cfra, int frame_ofs, const char *viewname)
910 {
911         SeqRenderData context;
912         ImBuf *ibuf;
913         int rectx, recty;
914         float render_size;
915         float proxy_size = 100.0;
916         short is_break = G.is_break;
917
918         render_size = sseq->render_size;
919         if (render_size == 0) {
920                 render_size = scene->r.size;
921         }
922         else {
923                 proxy_size = render_size;
924         }
925
926         if (render_size < 0) {
927                 return NULL;
928         }
929
930         rectx = (render_size * (float)scene->r.xsch) / 100.0f + 0.5f;
931         recty = (render_size * (float)scene->r.ysch) / 100.0f + 0.5f;
932
933         BKE_sequencer_new_render_data(
934                 bmain->eval_ctx, bmain, scene,
935                 rectx, recty, proxy_size,
936                 &context);
937         context.view_id = BKE_scene_multiview_view_id_get(&scene->r, viewname);
938
939         /* sequencer could start rendering, in this case we need to be sure it wouldn't be canceled
940          * by Esc pressed somewhere in the past
941          */
942         G.is_break = false;
943
944         if (special_seq_update)
945                 ibuf = BKE_sequencer_give_ibuf_direct(&context, cfra + frame_ofs, special_seq_update);
946         else if (!U.prefetchframes) // XXX || (G.f & G_PLAYANIM) == 0) {
947                 ibuf = BKE_sequencer_give_ibuf(&context, cfra + frame_ofs, sseq->chanshown);
948         else
949                 ibuf = BKE_sequencer_give_ibuf_threaded(&context, cfra + frame_ofs, sseq->chanshown);
950
951         /* restore state so real rendering would be canceled (if needed) */
952         G.is_break = is_break;
953
954         return ibuf;
955 }
956
957 static void sequencer_check_scopes(SequencerScopes *scopes, ImBuf *ibuf)
958 {
959         if (scopes->reference_ibuf != ibuf) {
960                 if (scopes->zebra_ibuf) {
961                         IMB_freeImBuf(scopes->zebra_ibuf);
962                         scopes->zebra_ibuf = NULL;
963                 }
964
965                 if (scopes->waveform_ibuf) {
966                         IMB_freeImBuf(scopes->waveform_ibuf);
967                         scopes->waveform_ibuf = NULL;
968                 }
969
970                 if (scopes->sep_waveform_ibuf) {
971                         IMB_freeImBuf(scopes->sep_waveform_ibuf);
972                         scopes->sep_waveform_ibuf = NULL;
973                 }
974
975                 if (scopes->vector_ibuf) {
976                         IMB_freeImBuf(scopes->vector_ibuf);
977                         scopes->vector_ibuf = NULL;
978                 }
979
980                 if (scopes->histogram_ibuf) {
981                         IMB_freeImBuf(scopes->histogram_ibuf);
982                         scopes->histogram_ibuf = NULL;
983                 }
984         }
985 }
986
987 static ImBuf *sequencer_make_scope(Scene *scene, ImBuf *ibuf, ImBuf *(*make_scope_cb) (ImBuf *ibuf))
988 {
989         ImBuf *display_ibuf = IMB_dupImBuf(ibuf);
990         ImBuf *scope;
991         
992         IMB_colormanagement_imbuf_make_display_space(display_ibuf, &scene->view_settings,
993                                                              &scene->display_settings);
994
995         scope = make_scope_cb(display_ibuf);
996
997         IMB_freeImBuf(display_ibuf);
998
999         return scope;
1000 }
1001
1002 static void sequencer_display_size(Scene *scene, SpaceSeq *sseq, float r_viewrect[2])
1003 {
1004         float render_size, proxy_size;
1005
1006         if (sseq->render_size == SEQ_PROXY_RENDER_SIZE_SCENE) {
1007                 render_size = (float)scene->r.size / 100.0f;
1008                 proxy_size = 1.0f;
1009         }
1010         else {
1011                 render_size = (float)sseq->render_size / 100.0f;
1012                 proxy_size = render_size;
1013         }
1014
1015         r_viewrect[0] = (render_size * (float)scene->r.xsch);
1016         r_viewrect[1] = (render_size * (float)scene->r.ysch);
1017
1018         /* rectx = viewrectx + 0.5f; */ /* UNUSED */
1019         /* recty = viewrecty + 0.5f; */ /* UNUSED */
1020
1021         if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1022                 r_viewrect[0] *= scene->r.xasp / scene->r.yasp;
1023                 r_viewrect[0] /= proxy_size;
1024                 r_viewrect[1] /= proxy_size;
1025         }
1026 }
1027
1028 static void sequencer_draw_gpencil(const bContext *C)
1029 {
1030         /* draw grease-pencil (image aligned) */
1031         ED_gpencil_draw_2dimage(C);
1032
1033         /* ortho at pixel level */
1034         UI_view2d_view_restore(C);
1035
1036         /* draw grease-pencil (screen aligned) */
1037         ED_gpencil_draw_view2d(C, 0);
1038 }
1039
1040 /* draws content borders plus safety borders if needed */
1041 static void sequencer_draw_borders(const SpaceSeq *sseq, const View2D *v2d, const Scene *scene)
1042 {
1043         float x1 = v2d->tot.xmin;
1044         float y1 = v2d->tot.ymin;
1045         float x2 = v2d->tot.xmax;
1046         float y2 = v2d->tot.ymax;
1047
1048         glLineWidth(1.0f);
1049
1050         /* border */
1051         setlinestyle(3);
1052
1053         UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 1.0, 0);
1054
1055         glBegin(GL_LINE_LOOP);
1056         glVertex2f(x1 - 0.5f, y1 - 0.5f);
1057         glVertex2f(x1 - 0.5f, y2 + 0.5f);
1058         glVertex2f(x2 + 0.5f, y2 + 0.5f);
1059         glVertex2f(x2 + 0.5f, y1 - 0.5f);
1060         glEnd();
1061
1062         /* safety border */
1063         if (sseq->flag & SEQ_SHOW_SAFE_MARGINS) {
1064                 UI_draw_safe_areas(
1065                         x1, x2, y1, y2,
1066                         scene->safe_areas.title,
1067                         scene->safe_areas.action);
1068
1069                 if (sseq->flag & SEQ_SHOW_SAFE_CENTER) {
1070                         UI_draw_safe_areas(
1071                                 x1, x2, y1, y2,
1072                                 scene->safe_areas.title_center,
1073                                 scene->safe_areas.action_center);
1074                 }
1075         }
1076
1077         setlinestyle(0);
1078 }
1079
1080 /* draws checkerboard background for transparent content */
1081 static void sequencer_draw_background(
1082         const SpaceSeq *sseq, View2D *v2d, const float viewrect[2], const bool draw_overlay)
1083 {
1084         /* setting up the view */
1085         UI_view2d_totRect_set(v2d, viewrect[0] + 0.5f, viewrect[1] + 0.5f);
1086         UI_view2d_curRect_validate(v2d);
1087         UI_view2d_view_ortho(v2d);
1088
1089         /* only draw alpha for main buffer */
1090         if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1091                 if ((sseq->flag & SEQ_USE_ALPHA) && !draw_overlay) {
1092                         glEnable(GL_BLEND);
1093                         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1094
1095                         fdrawcheckerboard(v2d->tot.xmin, v2d->tot.ymin, v2d->tot.xmax, v2d->tot.ymax);
1096                         glColor4f(1.0, 1.0, 1.0, 1.0);
1097                 }
1098         }
1099 }
1100
1101 void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq, int cfra, int frame_ofs, bool draw_overlay, bool draw_backdrop)
1102 {
1103         struct Main *bmain = CTX_data_main(C);
1104         struct ImBuf *ibuf = NULL;
1105         struct ImBuf *scope = NULL;
1106         struct View2D *v2d = &ar->v2d;
1107         /* int rectx, recty; */ /* UNUSED */
1108         float viewrect[2];
1109         float col[3];
1110         GLuint texid;
1111         void *display_buffer;
1112         void *cache_handle = NULL;
1113         const bool is_imbuf = ED_space_sequencer_check_show_imbuf(sseq);
1114         int format, type;
1115         bool glsl_used = false;
1116         const bool draw_gpencil = ((sseq->flag & SEQ_SHOW_GPENCIL) && sseq->gpd);
1117         const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME};
1118         bool draw_metadata = false;
1119
1120         if (G.is_rendering == false && (scene->r.seq_prev_type) == OB_RENDER) {
1121                 /* stop all running jobs, except screen one. currently previews frustrate Render
1122                  * needed to make so sequencer's rendering doesn't conflict with compositor
1123                  */
1124                 WM_jobs_kill_type(CTX_wm_manager(C), NULL, WM_JOB_TYPE_COMPOSITE);
1125
1126                 /* in case of final rendering used for preview, kill all previews,
1127                  * otherwise threading conflict will happen in rendering module
1128                  */
1129                 WM_jobs_kill_type(CTX_wm_manager(C), NULL, WM_JOB_TYPE_RENDER_PREVIEW);
1130         }
1131
1132         if ((!draw_overlay || sseq->overlay_type == SEQ_DRAW_OVERLAY_REFERENCE) && !draw_backdrop) {
1133                 UI_GetThemeColor3fv(TH_SEQ_PREVIEW, col);
1134                 glClearColor(col[0], col[1], col[2], 0.0);
1135                 glClear(GL_COLOR_BUFFER_BIT);
1136         }
1137
1138         /* without this colors can flicker from previous opengl state */
1139         glColor4ub(255, 255, 255, 255);
1140
1141         /* only initialize the preview if a render is in progress */
1142         if (G.is_rendering)
1143                 return;
1144
1145         if (sseq->render_size == SEQ_PROXY_RENDER_SIZE_NONE) {
1146                 return;
1147         }
1148
1149         /* for now we only support Left/Right */
1150         ibuf = sequencer_ibuf_get(bmain, scene, sseq, cfra, frame_ofs, names[sseq->multiview_eye]);
1151
1152         if ((ibuf == NULL) ||
1153             (ibuf->rect == NULL && ibuf->rect_float == NULL))
1154         {
1155                 /* gpencil can also be drawn without a valid imbuf */
1156                 if ((draw_gpencil && is_imbuf) && !draw_overlay) {
1157                         sequencer_display_size(scene, sseq, viewrect);
1158
1159                         sequencer_draw_background(sseq, v2d, viewrect, false);
1160                         sequencer_draw_borders(sseq, v2d, scene);
1161
1162                         sequencer_draw_gpencil(C);
1163                 }
1164                 return;
1165         }
1166
1167         sequencer_display_size(scene, sseq, viewrect);
1168
1169         if (!draw_backdrop && (sseq->mainb != SEQ_DRAW_IMG_IMBUF || sseq->zebra != 0)) {
1170                 SequencerScopes *scopes = &sseq->scopes;
1171
1172                 sequencer_check_scopes(scopes, ibuf);
1173
1174                 switch (sseq->mainb) {
1175                         case SEQ_DRAW_IMG_IMBUF:
1176                                 if (!scopes->zebra_ibuf) {
1177                                         ImBuf *display_ibuf = IMB_dupImBuf(ibuf);
1178
1179                                         if (display_ibuf->rect_float) {
1180                                                 IMB_colormanagement_imbuf_make_display_space(display_ibuf, &scene->view_settings,
1181                                                                                              &scene->display_settings);
1182                                         }
1183                                         scopes->zebra_ibuf = make_zebra_view_from_ibuf(display_ibuf, sseq->zebra);
1184                                         IMB_freeImBuf(display_ibuf);
1185                                 }
1186                                 scope = scopes->zebra_ibuf;
1187                                 break;
1188                         case SEQ_DRAW_IMG_WAVEFORM:
1189                                 if ((sseq->flag & SEQ_DRAW_COLOR_SEPARATED) != 0) {
1190                                         if (!scopes->sep_waveform_ibuf)
1191                                                 scopes->sep_waveform_ibuf = sequencer_make_scope(scene, ibuf, make_sep_waveform_view_from_ibuf);
1192                                         scope = scopes->sep_waveform_ibuf;
1193                                 }
1194                                 else {
1195                                         if (!scopes->waveform_ibuf)
1196                                                 scopes->waveform_ibuf = sequencer_make_scope(scene, ibuf, make_waveform_view_from_ibuf);
1197                                         scope = scopes->waveform_ibuf;
1198                                 }
1199                                 break;
1200                         case SEQ_DRAW_IMG_VECTORSCOPE:
1201                                 if (!scopes->vector_ibuf)
1202                                         scopes->vector_ibuf = sequencer_make_scope(scene, ibuf, make_vectorscope_view_from_ibuf);
1203                                 scope = scopes->vector_ibuf;
1204                                 break;
1205                         case SEQ_DRAW_IMG_HISTOGRAM:
1206                                 if (!scopes->histogram_ibuf)
1207                                         scopes->histogram_ibuf = sequencer_make_scope(scene, ibuf, make_histogram_view_from_ibuf);
1208                                 scope = scopes->histogram_ibuf;
1209                                 break;
1210                 }
1211
1212                 /* future files may have new scopes we don't catch above */
1213                 if (scope) {
1214                         scopes->reference_ibuf = ibuf;
1215                         if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1216                                 /* scopes drawn in image preview use viewrect from orig ibuf - currently that's only zebra */
1217                         }
1218                         else {
1219                                 viewrect[0] = scope->x;
1220                                 viewrect[1] = scope->y;
1221                         }
1222                 }
1223                 else {
1224                         scopes->reference_ibuf = NULL;
1225                 }
1226         }
1227
1228         if (!draw_backdrop) {
1229                 sequencer_draw_background(sseq, v2d, viewrect, draw_overlay);
1230         }
1231
1232         if (scope) {
1233                 IMB_freeImBuf(ibuf);
1234                 ibuf = scope;
1235
1236                 if (ibuf->rect_float && ibuf->rect == NULL) {
1237                         IMB_rect_from_float(ibuf);
1238                 }
1239
1240                 display_buffer = (unsigned char *)ibuf->rect;
1241                 format = GL_RGBA;
1242                 type = GL_UNSIGNED_BYTE;
1243         }
1244         else {
1245                 bool force_fallback = false;
1246
1247                 force_fallback |= (U.image_draw_method != IMAGE_DRAW_METHOD_GLSL);
1248                 force_fallback |= (ibuf->dither != 0.0f);
1249
1250                 if (force_fallback) {
1251                         /* Fallback to CPU based color space conversion */
1252                         glsl_used = false;
1253                         format = GL_RGBA;
1254                         type = GL_UNSIGNED_BYTE;
1255                         display_buffer = NULL;
1256                 }
1257                 else if (ibuf->rect_float) {
1258                         display_buffer = ibuf->rect_float;
1259
1260                         if (ibuf->channels == 4) {
1261                                 format = GL_RGBA;
1262                         }
1263                         else if (ibuf->channels == 3) {
1264                                 format = GL_RGB;
1265                         }
1266                         else {
1267                                 BLI_assert(!"Incompatible number of channels for float buffer in sequencer");
1268                                 format = GL_RGBA;
1269                                 display_buffer = NULL;
1270                         }
1271
1272                         type = GL_FLOAT;
1273
1274                         if (ibuf->float_colorspace) {
1275                                 glsl_used = IMB_colormanagement_setup_glsl_draw_from_space_ctx(C, ibuf->float_colorspace, ibuf->dither, true);
1276                         }
1277                         else {
1278                                 glsl_used = IMB_colormanagement_setup_glsl_draw_ctx(C, ibuf->dither, true);
1279                         }
1280                 }
1281                 else if (ibuf->rect) {
1282                         display_buffer = ibuf->rect;
1283                         format = GL_RGBA;
1284                         type = GL_UNSIGNED_BYTE;
1285
1286                         glsl_used = IMB_colormanagement_setup_glsl_draw_from_space_ctx(C, ibuf->rect_colorspace, ibuf->dither, false);
1287                 }
1288                 else {
1289                         format = GL_RGBA;
1290                         type = GL_UNSIGNED_BYTE;
1291                         display_buffer = NULL;
1292                 }
1293
1294                 /* there's a data to be displayed, but GLSL is not initialized
1295                  * properly, in this case we fallback to CPU-based display transform
1296                  */
1297                 if ((ibuf->rect || ibuf->rect_float) && !glsl_used) {
1298                         display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle);
1299                         format = GL_RGBA;
1300                         type = GL_UNSIGNED_BYTE;
1301                 }
1302         }
1303
1304         glColor4f(1.0, 1.0, 1.0, 1.0);
1305
1306         GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR);
1307         glGenTextures(1, (GLuint *)&texid);
1308
1309         glBindTexture(GL_TEXTURE_2D, texid);
1310
1311         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1312         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1313
1314         if (type == GL_FLOAT)
1315                 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, ibuf->x, ibuf->y, 0, format, type, display_buffer);
1316         else
1317                 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ibuf->x, ibuf->y, 0, format, type, display_buffer);
1318
1319         if (draw_backdrop) {
1320                 glMatrixMode(GL_PROJECTION);
1321                 glPushMatrix();
1322                 glLoadIdentity();
1323                 glMatrixMode(GL_MODELVIEW);
1324                 glPushMatrix();
1325                 glLoadIdentity();
1326         }
1327         glBegin(GL_QUADS);
1328
1329         if (draw_overlay) {
1330                 if (sseq->overlay_type == SEQ_DRAW_OVERLAY_RECT) {
1331                         rctf tot_clip;
1332                         tot_clip.xmin = v2d->tot.xmin + (fabsf(BLI_rctf_size_x(&v2d->tot)) * scene->ed->over_border.xmin);
1333                         tot_clip.ymin = v2d->tot.ymin + (fabsf(BLI_rctf_size_y(&v2d->tot)) * scene->ed->over_border.ymin);
1334                         tot_clip.xmax = v2d->tot.xmin + (fabsf(BLI_rctf_size_x(&v2d->tot)) * scene->ed->over_border.xmax);
1335                         tot_clip.ymax = v2d->tot.ymin + (fabsf(BLI_rctf_size_y(&v2d->tot)) * scene->ed->over_border.ymax);
1336
1337                         glTexCoord2f(scene->ed->over_border.xmin, scene->ed->over_border.ymin); glVertex2f(tot_clip.xmin, tot_clip.ymin);
1338                         glTexCoord2f(scene->ed->over_border.xmin, scene->ed->over_border.ymax); glVertex2f(tot_clip.xmin, tot_clip.ymax);
1339                         glTexCoord2f(scene->ed->over_border.xmax, scene->ed->over_border.ymax); glVertex2f(tot_clip.xmax, tot_clip.ymax);
1340                         glTexCoord2f(scene->ed->over_border.xmax, scene->ed->over_border.ymin); glVertex2f(tot_clip.xmax, tot_clip.ymin);
1341                 }
1342                 else if (sseq->overlay_type == SEQ_DRAW_OVERLAY_REFERENCE) {
1343                         glTexCoord2f(0.0f, 0.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymin);
1344                         glTexCoord2f(0.0f, 1.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymax);
1345                         glTexCoord2f(1.0f, 1.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymax);
1346                         glTexCoord2f(1.0f, 0.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymin);
1347                 }
1348         }
1349         else if (draw_backdrop) {
1350                 float aspect;
1351                 float image_aspect = viewrect[0] / viewrect[1];
1352                 float imagex, imagey;
1353
1354                 aspect = BLI_rcti_size_x(&ar->winrct) / (float)BLI_rcti_size_y(&ar->winrct);
1355
1356                 if (aspect >= image_aspect) {
1357                         imagex = image_aspect / aspect;
1358                         imagey = 1.0f;
1359                 }
1360                 else {
1361                         imagex = 1.0f;
1362                         imagey = aspect / image_aspect;
1363                 }
1364
1365                 glTexCoord2f(0.0f, 0.0f); glVertex2f(-imagex, -imagey);
1366                 glTexCoord2f(0.0f, 1.0f); glVertex2f(-imagex, imagey);
1367                 glTexCoord2f(1.0f, 1.0f); glVertex2f(imagex, imagey);
1368                 glTexCoord2f(1.0f, 0.0f); glVertex2f(imagex, -imagey);
1369         }
1370         else {
1371                 draw_metadata = ((sseq->flag & SEQ_SHOW_METADATA) != 0);
1372
1373                 glTexCoord2f(0.0f, 0.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymin);
1374                 glTexCoord2f(0.0f, 1.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymax);
1375                 glTexCoord2f(1.0f, 1.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymax);
1376                 glTexCoord2f(1.0f, 0.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymin);
1377         }
1378         glEnd();
1379
1380         glBindTexture(GL_TEXTURE_2D, 0);
1381         GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
1382         if (sseq->mainb == SEQ_DRAW_IMG_IMBUF && sseq->flag & SEQ_USE_ALPHA)
1383                 glDisable(GL_BLEND);
1384         glDeleteTextures(1, &texid);
1385
1386         if (glsl_used)
1387                 IMB_colormanagement_finish_glsl_draw();
1388
1389         if (cache_handle)
1390                 IMB_display_buffer_release(cache_handle);
1391
1392         if (!scope)
1393                 IMB_freeImBuf(ibuf);
1394
1395         if (draw_metadata) {
1396                 ED_region_image_metadata_draw(0.0, 0.0, ibuf, &v2d->tot, 1.0, 1.0);
1397         }
1398
1399         if (draw_backdrop) {
1400                 glPopMatrix();
1401                 glMatrixMode(GL_PROJECTION);
1402                 glPopMatrix();
1403                 glMatrixMode(GL_MODELVIEW);
1404                 return;
1405         }
1406
1407         if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1408                 sequencer_draw_borders(sseq, v2d, scene);
1409         }
1410
1411         if (draw_gpencil && is_imbuf) {
1412                 sequencer_draw_gpencil(C);
1413         }
1414         else {
1415                 /* ortho at pixel level */
1416                 UI_view2d_view_restore(C);
1417         }
1418
1419
1420         /* NOTE: sequencer mask editing isnt finished, the draw code is working but editing not,
1421          * for now just disable drawing since the strip frame will likely be offset */
1422
1423         //if (sc->mode == SC_MODE_MASKEDIT) {
1424         if (0 && sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1425                 Mask *mask = BKE_sequencer_mask_get(scene);
1426
1427                 if (mask) {
1428                         int width, height;
1429                         float aspx = 1.0f, aspy = 1.0f;
1430                         // ED_mask_get_size(C, &width, &height);
1431
1432                         //Scene *scene = CTX_data_scene(C);
1433                         width = (scene->r.size * scene->r.xsch) / 100;
1434                         height = (scene->r.size * scene->r.ysch) / 100;
1435
1436                         ED_mask_draw_region(mask, ar,
1437                                             0, 0, 0,  /* TODO */
1438                                             width, height,
1439                                             aspx, aspy,
1440                                             false, true,
1441                                             NULL, C);
1442                 }
1443         }
1444 }
1445
1446 #if 0
1447 void drawprefetchseqspace(Scene *scene, ARegion *UNUSED(ar), SpaceSeq *sseq)
1448 {
1449         int rectx, recty;
1450         int render_size = sseq->render_size;
1451         int proxy_size = 100.0; 
1452         if (render_size == 0) {
1453                 render_size = scene->r.size;
1454         }
1455         else {
1456                 proxy_size = render_size;
1457         }
1458         if (render_size < 0) {
1459                 return;
1460         }
1461
1462         rectx = (render_size * scene->r.xsch) / 100;
1463         recty = (render_size * scene->r.ysch) / 100;
1464
1465         if (sseq->mainb != SEQ_DRAW_SEQUENCE) {
1466                 give_ibuf_prefetch_request(
1467                     rectx, recty, (scene->r.cfra), sseq->chanshown,
1468                     proxy_size);
1469         }
1470 }
1471 #endif
1472
1473 /* draw backdrop of the sequencer strips view */
1474 static void draw_seq_backdrop(View2D *v2d)
1475 {
1476         int i;
1477         
1478         /* darker gray overlay over the view backdrop */
1479         UI_ThemeColorShade(TH_BACK, -20);
1480         glRectf(v2d->cur.xmin,  -1.0,  v2d->cur.xmax,  1.0);
1481
1482         /* Alternating horizontal stripes */
1483         i = max_ii(1, ((int)v2d->cur.ymin) - 1);
1484
1485         glBegin(GL_QUADS);
1486         while (i < v2d->cur.ymax) {
1487                 if (((int)i) & 1)
1488                         UI_ThemeColorShade(TH_BACK, -15);
1489                 else
1490                         UI_ThemeColorShade(TH_BACK, -25);
1491                         
1492                 glVertex2f(v2d->cur.xmax, i);
1493                 glVertex2f(v2d->cur.xmin, i);
1494                 glVertex2f(v2d->cur.xmin, i + 1);
1495                 glVertex2f(v2d->cur.xmax, i + 1);
1496
1497                 i += 1.0;
1498         }
1499         glEnd();
1500         
1501         /* Darker lines separating the horizontal bands */
1502         i = max_ii(1, ((int)v2d->cur.ymin) - 1);
1503         UI_ThemeColor(TH_GRID);
1504         
1505         glBegin(GL_LINES);
1506         while (i < v2d->cur.ymax) {
1507                 glVertex2f(v2d->cur.xmax, i);
1508                 glVertex2f(v2d->cur.xmin, i);
1509                         
1510                 i += 1.0;
1511         }
1512         glEnd();
1513 }
1514
1515 /* draw the contents of the sequencer strips view */
1516 static void draw_seq_strips(const bContext *C, Editing *ed, ARegion *ar)
1517 {
1518         Scene *scene = CTX_data_scene(C);
1519         View2D *v2d = &ar->v2d;
1520         SpaceSeq *sseq = CTX_wm_space_seq(C);
1521         Sequence *last_seq = BKE_sequencer_active_get(scene);
1522         int sel = 0, j;
1523         float pixelx = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask);
1524         
1525         /* loop through twice, first unselected, then selected */
1526         for (j = 0; j < 2; j++) {
1527                 Sequence *seq;
1528                 int outline_tint = (j) ? -60 : -150; /* highlighting around strip edges indicating selection */
1529                 
1530                 /* loop through strips, checking for those that are visible */
1531                 for (seq = ed->seqbasep->first; seq; seq = seq->next) {
1532                         /* boundbox and selection tests for NOT drawing the strip... */
1533                         if ((seq->flag & SELECT) != sel) continue;
1534                         else if (seq == last_seq) continue;
1535                         else if (min_ii(seq->startdisp, seq->start) > v2d->cur.xmax) continue;
1536                         else if (max_ii(seq->enddisp, seq->start + seq->len) < v2d->cur.xmin) continue;
1537                         else if (seq->machine + 1.0f < v2d->cur.ymin) continue;
1538                         else if (seq->machine > v2d->cur.ymax) continue;
1539                         
1540                         /* strip passed all tests unscathed... so draw it now */
1541                         draw_seq_strip(C, sseq, scene, ar, seq, outline_tint, pixelx);
1542                 }
1543                 
1544                 /* draw selected next time round */
1545                 sel = SELECT;
1546         }
1547         
1548         /* draw the last selected last (i.e. 'active' in other parts of Blender), removes some overlapping error */
1549         if (last_seq)
1550                 draw_seq_strip(C, sseq, scene, ar, last_seq, 120, pixelx);
1551
1552         /* draw highlight when previewing a single strip */
1553         if (special_seq_update) {
1554                 const Sequence *seq = special_seq_update;
1555                 glEnable(GL_BLEND);
1556                 glColor4ub(255, 255, 255, 48);
1557                 glRectf(seq->startdisp, seq->machine + SEQ_STRIP_OFSBOTTOM, seq->enddisp, seq->machine + SEQ_STRIP_OFSTOP);
1558                 glDisable(GL_BLEND);
1559         }
1560 }
1561
1562 static void seq_draw_sfra_efra(Scene *scene, View2D *v2d)
1563 {
1564         const Editing *ed = BKE_sequencer_editing_get(scene, false);
1565         const int frame_sta = PSFRA;
1566         const int frame_end = PEFRA + 1;
1567
1568         glEnable(GL_BLEND);
1569         
1570         /* draw darkened area outside of active timeline 
1571          * frame range used is preview range or scene range */
1572         UI_ThemeColorShadeAlpha(TH_BACK, -25, -100);
1573
1574         if (frame_sta < frame_end) {
1575                 glRectf(v2d->cur.xmin, v2d->cur.ymin, (float)frame_sta, v2d->cur.ymax);
1576                 glRectf((float)frame_end, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
1577         }
1578         else {
1579                 glRectf(v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
1580         }
1581
1582         UI_ThemeColorShade(TH_BACK, -60);
1583         /* thin lines where the actual frames are */
1584         fdrawline(frame_sta, v2d->cur.ymin, frame_sta, v2d->cur.ymax);
1585         fdrawline(frame_end, v2d->cur.ymin, frame_end, v2d->cur.ymax);
1586
1587         if (ed && !BLI_listbase_is_empty(&ed->metastack)) {
1588                 MetaStack *ms = ed->metastack.last;
1589
1590                 glColor4ub(255, 255, 255, 8);
1591                 glRectf(ms->disp_range[0], v2d->cur.ymin, ms->disp_range[1], v2d->cur.ymax);
1592
1593                 UI_ThemeColorShade(TH_BACK, -40);
1594
1595                 fdrawline(ms->disp_range[0], v2d->cur.ymin, ms->disp_range[0], v2d->cur.ymax);
1596                 fdrawline(ms->disp_range[1], v2d->cur.ymin, ms->disp_range[1], v2d->cur.ymax);
1597         }
1598
1599         glDisable(GL_BLEND);
1600 }
1601
1602 /* Draw Timeline/Strip Editor Mode for Sequencer */
1603 void draw_timeline_seq(const bContext *C, ARegion *ar)
1604 {
1605         Scene *scene = CTX_data_scene(C);
1606         Editing *ed = BKE_sequencer_editing_get(scene, false);
1607         SpaceSeq *sseq = CTX_wm_space_seq(C);
1608         View2D *v2d = &ar->v2d;
1609         View2DScrollers *scrollers;
1610         short unit = 0, flag = 0;
1611         float col[3];
1612         
1613         /* clear and setup matrix */
1614         UI_GetThemeColor3fv(TH_BACK, col);
1615         if (ed && ed->metastack.first) 
1616                 glClearColor(col[0], col[1], col[2] - 0.1f, 0.0f);
1617         else 
1618                 glClearColor(col[0], col[1], col[2], 0.0f);
1619         glClear(GL_COLOR_BUFFER_BIT);
1620
1621         UI_view2d_view_ortho(v2d);
1622         
1623         
1624         /* calculate extents of sequencer strips/data 
1625          * NOTE: needed for the scrollers later
1626          */
1627         boundbox_seq(scene, &v2d->tot);
1628         
1629         
1630         /* draw backdrop */
1631         draw_seq_backdrop(v2d);
1632         
1633         /* regular grid-pattern over the rest of the view (i.e. 25-frame grid lines) */
1634         // NOTE: the gridlines are currently spaced every 25 frames, which is only fine for 25 fps, but maybe not for 30...
1635         UI_view2d_constant_grid_draw(v2d);
1636
1637         /* Only draw backdrop in pure sequence view. */
1638         if (sseq->view == SEQ_VIEW_SEQUENCE && sseq->draw_flag & SEQ_DRAW_BACKDROP) {
1639                 draw_image_seq(C, scene, ar, sseq, scene->r.cfra, 0, false, true);
1640                 UI_view2d_view_ortho(v2d);
1641         }
1642                 
1643         ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
1644         
1645         seq_draw_sfra_efra(scene, v2d);
1646
1647         /* sequence strips (if there is data available to be drawn) */
1648         if (ed) {
1649                 /* draw the data */
1650                 draw_seq_strips(C, ed, ar);
1651                 
1652                 /* text draw cached (for sequence names), in pixelspace now */
1653                 UI_view2d_text_cache_draw(ar);
1654         }
1655         
1656         /* current frame */
1657         UI_view2d_view_ortho(v2d);
1658         if ((sseq->flag & SEQ_DRAWFRAMES) == 0)      flag |= DRAWCFRA_UNIT_SECONDS;
1659         if ((sseq->flag & SEQ_NO_DRAW_CFRANUM) == 0) flag |= DRAWCFRA_SHOW_NUMBOX;
1660         ANIM_draw_cfra(C, v2d, flag);
1661         
1662         /* markers */
1663         UI_view2d_view_orthoSpecial(ar, v2d, 1);
1664         ED_markers_draw(C, DRAW_MARKERS_LINES | DRAW_MARKERS_MARGIN);
1665         
1666         /* preview range */
1667         UI_view2d_view_ortho(v2d);
1668         ANIM_draw_previewrange(C, v2d, 1);
1669
1670         /* overlap playhead */
1671         if (scene->ed && scene->ed->over_flag & SEQ_EDIT_OVERLAY_SHOW) {
1672                 int cfra_over = (scene->ed->over_flag & SEQ_EDIT_OVERLAY_ABS) ? scene->ed->over_cfra : scene->r.cfra + scene->ed->over_ofs;
1673                 glColor3f(0.2, 0.2, 0.2);
1674                 // glRectf(cfra_over, v2d->cur.ymin, scene->ed->over_ofs + scene->r.cfra + 1, v2d->cur.ymax);
1675
1676                 glBegin(GL_LINES);
1677                 glVertex2f(cfra_over, v2d->cur.ymin);
1678                 glVertex2f(cfra_over, v2d->cur.ymax);
1679                 glEnd();
1680
1681         }
1682         
1683         /* callback */
1684         ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
1685
1686         /* reset view matrix */
1687         UI_view2d_view_restore(C);
1688
1689         /* scrollers */
1690         unit = (sseq->flag & SEQ_DRAWFRAMES) ? V2D_UNIT_FRAMES : V2D_UNIT_SECONDS;
1691         scrollers = UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_UNIT_VALUES, V2D_GRID_CLAMP);
1692         UI_view2d_scrollers_draw(C, v2d, scrollers);
1693         UI_view2d_scrollers_free(scrollers);
1694 }
1695
1696