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