925804b8bb4414aacc08d605d8ed3d66533972b1
[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_simple_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 ((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 (!seq->sound->waveform) {
219                         if (!(sound->flags & SOUND_FLAGS_WAVEFORM_LOADING)) {
220                                 /* prevent sounds from reloading */
221                                 seq->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 = seq->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                 glEnable(GL_POLYGON_STIPPLE);
285                 glPolygonStipple(stipple_halftone);
286                 
287                 glEnable(GL_LINE_STIPPLE);
288                 glLineStipple(1, 0x8888);
289         }
290         else {
291                 glDisable(GL_POLYGON_STIPPLE);
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, 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 (seq->sound) {
544                         str_len = BLI_snprintf(str, sizeof(str), "%s: %s | %d",
545                                                name, seq->sound->name, seq->len);
546                 }
547                 else {
548                         str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
549                                                name, seq->len);
550                 }
551         }
552         else if (seq->type == SEQ_TYPE_MOVIE) {
553                 str_len = BLI_snprintf(str, sizeof(str), "%s: %s%s | %d",
554                                        name, seq->strip->dir, seq->strip->stripdata->name, seq->len);
555         }
556         else {
557                 /* should never get here!, but might with files from future */
558                 BLI_assert(0);
559
560                 str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
561                                        name, seq->len);
562         }
563         
564         if (seq->flag & SELECT) {
565                 col[0] = col[1] = col[2] = 255;
566         }
567         else if ((((int)background_col[0] + (int)background_col[1] + (int)background_col[2]) / 3) < 50) {
568                 col[0] = col[1] = col[2] = 80; /* use lighter text color for dark background */
569         }
570         else {
571                 col[0] = col[1] = col[2] = 0;
572         }
573         col[3] = 255;
574
575         rect.xmin = x1;
576         rect.ymin = y1;
577         rect.xmax = x2;
578         rect.ymax = y2;
579
580         UI_view2d_text_cache_add_rectf(v2d, &rect, str, str_len, col);
581 }
582
583 /* draws a shaded strip, made from gradient + flat color + gradient */
584 void draw_shadedstrip(Sequence *seq, unsigned char col[3], float x1, float y1, float x2, float y2)
585 {
586         float ymid1, ymid2;
587         
588         if (seq->flag & SEQ_MUTE) {
589                 glEnable(GL_POLYGON_STIPPLE);
590                 glPolygonStipple(stipple_halftone);
591         }
592         
593         ymid1 = (y2 - y1) * 0.25f + y1;
594         ymid2 = (y2 - y1) * 0.65f + y1;
595         
596         glShadeModel(GL_SMOOTH);
597         glBegin(GL_QUADS);
598         
599         if (seq->flag & SEQ_INVALID_EFFECT) { col[0] = 255; col[1] = 0; col[2] = 255; }
600         else if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, -50);
601         /* else UI_GetColorPtrShade3ubv(col, col, 0); */ /* DO NOTHING */
602         
603         glColor3ubv(col);
604         
605         glVertex2f(x1, y1);
606         glVertex2f(x2, y1);
607
608         if (seq->flag & SEQ_INVALID_EFFECT) { col[0] = 255; col[1] = 0; col[2] = 255; }
609         else if (seq->flag & SELECT) UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, 5);
610         else UI_GetColorPtrShade3ubv(col, col, -5);
611
612         glColor3ubv((GLubyte *)col);
613         
614         glVertex2f(x2, ymid1);
615         glVertex2f(x1, ymid1);
616         
617         glEnd();
618         
619         glRectf(x1,  ymid1,  x2,  ymid2);
620         
621         glBegin(GL_QUADS);
622         
623         glVertex2f(x1, ymid2);
624         glVertex2f(x2, ymid2);
625         
626         if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, -15);
627         else UI_GetColorPtrShade3ubv(col, col, 25);
628         
629         glColor3ubv((GLubyte *)col);
630         
631         glVertex2f(x2, y2);
632         glVertex2f(x1, y2);
633         
634         glEnd();
635         
636         if (seq->flag & SEQ_MUTE) {
637                 glDisable(GL_POLYGON_STIPPLE);
638         }
639 }
640
641 void draw_sequence_extensions(Scene *scene, ARegion *ar, Sequence *seq)
642 {
643         float x1, x2, y1, y2, pixely, a;
644         unsigned char col[3], blendcol[3];
645         View2D *v2d = &ar->v2d;
646         
647         x1 = seq->startdisp;
648         x2 = seq->enddisp;
649         
650         y1 = seq->machine + SEQ_STRIP_OFSBOTTOM;
651         y2 = seq->machine + SEQ_STRIP_OFSTOP;
652         
653         pixely = BLI_rctf_size_y(&v2d->cur) / BLI_rcti_size_y(&v2d->mask);
654         
655         if (pixely <= 0) return;  /* can happen when the view is split/resized */
656         
657         blendcol[0] = blendcol[1] = blendcol[2] = 120;
658         
659         if (seq->startofs) {
660                 glEnable(GL_BLEND);
661                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
662                 
663                 color3ubv_from_seq(scene, seq, col);
664                 
665                 if (seq->flag & SELECT) {
666                         UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.3, -40);
667                         glColor4ub(col[0], col[1], col[2], 170);
668                 }
669                 else {
670                         UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.6, 0);
671                         glColor4ub(col[0], col[1], col[2], 110);
672                 }
673                 
674                 glRectf((float)(seq->start), y1 - SEQ_STRIP_OFSBOTTOM, x1, y1);
675                 
676                 if (seq->flag & SELECT) glColor4ub(col[0], col[1], col[2], 255);
677                 else glColor4ub(col[0], col[1], col[2], 160);
678                 
679                 fdrawbox((float)(seq->start), y1 - SEQ_STRIP_OFSBOTTOM, x1, y1);  //outline
680                 
681                 glDisable(GL_BLEND);
682         }
683         if (seq->endofs) {
684                 glEnable(GL_BLEND);
685                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
686                 
687                 color3ubv_from_seq(scene, seq, col);
688                 
689                 if (seq->flag & SELECT) {
690                         UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.3, -40);
691                         glColor4ub(col[0], col[1], col[2], 170);
692                 }
693                 else {
694                         UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.6, 0);
695                         glColor4ub(col[0], col[1], col[2], 110);
696                 }
697                 
698                 glRectf(x2, y2, (float)(seq->start + seq->len), y2 + SEQ_STRIP_OFSBOTTOM);
699                 
700                 if (seq->flag & SELECT) glColor4ub(col[0], col[1], col[2], 255);
701                 else glColor4ub(col[0], col[1], col[2], 160);
702                 
703                 fdrawbox(x2, y2, (float)(seq->start + seq->len), y2 + SEQ_STRIP_OFSBOTTOM); //outline
704                 
705                 glDisable(GL_BLEND);
706         }
707         if (seq->startstill) {
708                 color3ubv_from_seq(scene, seq, col);
709                 UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.75, 40);
710                 glColor3ubv((GLubyte *)col);
711                 
712                 draw_shadedstrip(seq, col, x1, y1, (float)(seq->start), y2);
713                 
714                 /* feint pinstripes, helps see exactly which is extended and which isn't,
715                  * especially when the extension is very small */
716                 if (seq->flag & SELECT) UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, 24);
717                 else UI_GetColorPtrShade3ubv(col, col, -16);
718                 
719                 glColor3ubv((GLubyte *)col);
720                 
721                 for (a = y1; a < y2; a += pixely * 2.0f) {
722                         fdrawline(x1,  a,  (float)(seq->start),  a);
723                 }
724         }
725         if (seq->endstill) {
726                 color3ubv_from_seq(scene, seq, col);
727                 UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.75, 40);
728                 glColor3ubv((GLubyte *)col);
729                 
730                 draw_shadedstrip(seq, col, (float)(seq->start + seq->len), y1, x2, y2);
731                 
732                 /* feint pinstripes, helps see exactly which is extended and which isn't,
733                  * especially when the extension is very small */
734                 if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, 24);
735                 else UI_GetColorPtrShade3ubv(col, col, -16);
736                 
737                 glColor3ubv((GLubyte *)col);
738                 
739                 for (a = y1; a < y2; a += pixely * 2.0f) {
740                         fdrawline((float)(seq->start + seq->len),  a,  x2,  a);
741                 }
742         }
743 }
744
745
746 /*
747  * Draw a sequence strip, bounds check already made
748  * ARegion is currently only used to get the windows width in pixels
749  * so wave file sample drawing precision is zoom adjusted
750  */
751 static void draw_seq_strip(const bContext *C, SpaceSeq *sseq, Scene *scene, ARegion *ar, Sequence *seq, int outline_tint, float pixelx)
752 {
753         View2D *v2d = &ar->v2d;
754         float x1, x2, y1, y2;
755         unsigned char col[3], background_col[3], is_single_image;
756         const float handsize_clamped = draw_seq_handle_size_get_clamped(seq, pixelx);
757
758         /* we need to know if this is a single image/color or not for drawing */
759         is_single_image = (char)BKE_sequence_single_check(seq);
760         
761         /* body */
762         x1 = (seq->startstill) ? seq->start : seq->startdisp;
763         y1 = seq->machine + SEQ_STRIP_OFSBOTTOM;
764         x2 = (seq->endstill) ? (seq->start + seq->len) : seq->enddisp;
765         y2 = seq->machine + SEQ_STRIP_OFSTOP;
766
767
768         /* get the correct color per strip type*/
769         //color3ubv_from_seq(scene, seq, col);
770         color3ubv_from_seq(scene, seq, background_col);
771         
772         /* draw the main strip body */
773         if (is_single_image) {  /* single image */
774                 draw_shadedstrip(seq, background_col,
775                                  BKE_sequence_tx_get_final_left(seq, false), y1,
776                                  BKE_sequence_tx_get_final_right(seq, false), y2);
777         }
778         else {  /* normal operation */
779                 draw_shadedstrip(seq, background_col, x1, y1, x2, y2);
780         }
781
782         if (!is_single_image) {
783                 if ((sseq->draw_flag & SEQ_DRAW_OFFSET_EXT) || (seq == special_seq_update)) {
784                         draw_sequence_extensions(scene, ar, seq);
785                 }
786         }
787
788         draw_seq_handle(v2d, seq, handsize_clamped, SEQ_LEFTHANDLE);
789         draw_seq_handle(v2d, seq, handsize_clamped, SEQ_RIGHTHANDLE);
790         
791         /* draw the strip outline */
792         x1 = seq->startdisp;
793         x2 = seq->enddisp;
794         
795         /* draw sound wave */
796         if (seq->type == SEQ_TYPE_SOUND_RAM) {
797                 if (!(sseq->flag & SEQ_NO_WAVEFORMS)) {
798                         drawseqwave(C, sseq, scene, seq, x1, y1, x2, y2, BLI_rctf_size_x(&ar->v2d.cur) / ar->winx);
799                 }
800         }
801
802         /* draw lock */
803         if (seq->flag & SEQ_LOCK) {
804                 glEnable(GL_POLYGON_STIPPLE);
805                 glEnable(GL_BLEND);
806
807                 /* light stripes */
808                 glColor4ub(255, 255, 255, 32);
809                 glPolygonStipple(stipple_diag_stripes_pos);
810                 glRectf(x1, y1, x2, y2);
811
812                 /* dark stripes */
813                 glColor4ub(0, 0, 0, 32);
814                 glPolygonStipple(stipple_diag_stripes_neg);
815                 glRectf(x1, y1, x2, y2);
816
817                 glDisable(GL_POLYGON_STIPPLE);
818                 glDisable(GL_BLEND);
819         }
820
821         if (!BKE_sequence_is_valid_check(seq)) {
822                 glEnable(GL_POLYGON_STIPPLE);
823
824                 /* panic! */
825                 glColor4ub(255, 0, 0, 255);
826                 glPolygonStipple(stipple_diag_stripes_pos);
827                 glRectf(x1, y1, x2, y2);
828
829                 glDisable(GL_POLYGON_STIPPLE);
830         }
831
832         color3ubv_from_seq(scene, seq, col);
833         if ((G.moving & G_TRANSFORM_SEQ) && (seq->flag & SELECT)) {
834                 if (seq->flag & SEQ_OVERLAP) {
835                         col[0] = 255; col[1] = col[2] = 40;
836                 }
837                 else
838                         UI_GetColorPtrShade3ubv(col, col, 120 + outline_tint);
839         }
840         else
841                 UI_GetColorPtrShade3ubv(col, col, outline_tint);
842         
843         glColor3ubv((GLubyte *)col);
844         
845         if (seq->flag & SEQ_MUTE) {
846                 glEnable(GL_LINE_STIPPLE);
847                 glLineStipple(1, 0x8888);
848         }
849         
850         UI_draw_roundbox_shade_x(GL_LINE_LOOP, x1, y1, x2, y2, 0.0, 0.1, 0.0);
851         
852         if (seq->flag & SEQ_MUTE) {
853                 glDisable(GL_LINE_STIPPLE);
854         }
855         
856         if ((seq->type == SEQ_TYPE_META) ||
857             ((seq->type == SEQ_TYPE_SCENE) && (seq->flag & SEQ_SCENE_STRIPS)))
858         {
859                 drawmeta_contents(scene, seq, x1, y1, x2, y2);
860         }
861         
862         /* calculate if seq is long enough to print a name */
863         x1 = seq->startdisp + handsize_clamped;
864         x2 = seq->enddisp   - handsize_clamped;
865
866         /* info text on the strip */
867         if (x1 < v2d->cur.xmin) x1 = v2d->cur.xmin;
868         else if (x1 > v2d->cur.xmax) x1 = v2d->cur.xmax;
869         if (x2 < v2d->cur.xmin) x2 = v2d->cur.xmin;
870         else if (x2 > v2d->cur.xmax) x2 = v2d->cur.xmax;
871
872         /* nice text here would require changing the view matrix for texture text */
873         if ((x2 - x1) / pixelx > 32) {
874                 draw_seq_text(v2d, seq, x1, x2, y1, y2, background_col);
875         }
876 }
877
878 void sequencer_special_update_set(Sequence *seq)
879 {
880         special_seq_update = seq;
881 }
882
883 Sequence *ED_sequencer_special_preview_get(void)
884 {
885         return special_seq_update;
886 }
887
888 void ED_sequencer_special_preview_set(bContext *C, const int mval[2])
889 {
890         Scene *scene = CTX_data_scene(C);
891         ARegion *ar = CTX_wm_region(C);
892         int hand;
893         Sequence *seq;
894         seq = find_nearest_seq(scene, &ar->v2d, &hand, mval);
895         sequencer_special_update_set(seq);
896 }
897
898 void ED_sequencer_special_preview_clear(void)
899 {
900         sequencer_special_update_set(NULL);
901 }
902
903 ImBuf *sequencer_ibuf_get(struct Main *bmain, Scene *scene, SpaceSeq *sseq, int cfra, int frame_ofs, const char *viewname)
904 {
905         SeqRenderData context;
906         ImBuf *ibuf;
907         int rectx, recty;
908         float render_size;
909         float proxy_size = 100.0;
910         short is_break = G.is_break;
911
912         render_size = sseq->render_size;
913         if (render_size == 0) {
914                 render_size = scene->r.size;
915         }
916         else {
917                 proxy_size = render_size;
918         }
919
920         if (render_size < 0) {
921                 return NULL;
922         }
923
924         rectx = (render_size * (float)scene->r.xsch) / 100.0f + 0.5f;
925         recty = (render_size * (float)scene->r.ysch) / 100.0f + 0.5f;
926
927         BKE_sequencer_new_render_data(
928                 bmain->eval_ctx, bmain, scene,
929                 rectx, recty, proxy_size,
930                 &context);
931         context.view_id = BKE_scene_multiview_view_id_get(&scene->r, viewname);
932
933         /* sequencer could start rendering, in this case we need to be sure it wouldn't be canceled
934          * by Esc pressed somewhere in the past
935          */
936         G.is_break = false;
937
938         if (special_seq_update)
939                 ibuf = BKE_sequencer_give_ibuf_direct(&context, cfra + frame_ofs, special_seq_update);
940         else if (!U.prefetchframes) // XXX || (G.f & G_PLAYANIM) == 0) {
941                 ibuf = BKE_sequencer_give_ibuf(&context, cfra + frame_ofs, sseq->chanshown);
942         else
943                 ibuf = BKE_sequencer_give_ibuf_threaded(&context, cfra + frame_ofs, sseq->chanshown);
944
945         /* restore state so real rendering would be canceled (if needed) */
946         G.is_break = is_break;
947
948         return ibuf;
949 }
950
951 static void sequencer_check_scopes(SequencerScopes *scopes, ImBuf *ibuf)
952 {
953         if (scopes->reference_ibuf != ibuf) {
954                 if (scopes->zebra_ibuf) {
955                         IMB_freeImBuf(scopes->zebra_ibuf);
956                         scopes->zebra_ibuf = NULL;
957                 }
958
959                 if (scopes->waveform_ibuf) {
960                         IMB_freeImBuf(scopes->waveform_ibuf);
961                         scopes->waveform_ibuf = NULL;
962                 }
963
964                 if (scopes->sep_waveform_ibuf) {
965                         IMB_freeImBuf(scopes->sep_waveform_ibuf);
966                         scopes->sep_waveform_ibuf = NULL;
967                 }
968
969                 if (scopes->vector_ibuf) {
970                         IMB_freeImBuf(scopes->vector_ibuf);
971                         scopes->vector_ibuf = NULL;
972                 }
973
974                 if (scopes->histogram_ibuf) {
975                         IMB_freeImBuf(scopes->histogram_ibuf);
976                         scopes->histogram_ibuf = NULL;
977                 }
978         }
979 }
980
981 static ImBuf *sequencer_make_scope(Scene *scene, ImBuf *ibuf, ImBuf *(*make_scope_cb) (ImBuf *ibuf))
982 {
983         ImBuf *display_ibuf = IMB_dupImBuf(ibuf);
984         ImBuf *scope;
985         
986         IMB_colormanagement_imbuf_make_display_space(display_ibuf, &scene->view_settings,
987                                                              &scene->display_settings);
988
989         scope = make_scope_cb(display_ibuf);
990
991         IMB_freeImBuf(display_ibuf);
992
993         return scope;
994 }
995
996 static void sequencer_display_size(Scene *scene, SpaceSeq *sseq, float r_viewrect[2])
997 {
998         float render_size, proxy_size;
999
1000         if (sseq->render_size == SEQ_PROXY_RENDER_SIZE_SCENE) {
1001                 render_size = (float)scene->r.size / 100.0f;
1002                 proxy_size = 1.0f;
1003         }
1004         else {
1005                 render_size = (float)sseq->render_size / 100.0f;
1006                 proxy_size = render_size;
1007         }
1008
1009         r_viewrect[0] = (render_size * (float)scene->r.xsch);
1010         r_viewrect[1] = (render_size * (float)scene->r.ysch);
1011
1012         /* rectx = viewrectx + 0.5f; */ /* UNUSED */
1013         /* recty = viewrecty + 0.5f; */ /* UNUSED */
1014
1015         if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1016                 r_viewrect[0] *= scene->r.xasp / scene->r.yasp;
1017                 r_viewrect[0] /= proxy_size;
1018                 r_viewrect[1] /= proxy_size;
1019         }
1020 }
1021
1022 static void sequencer_draw_gpencil(const bContext *C)
1023 {
1024         /* draw grease-pencil (image aligned) */
1025         ED_gpencil_draw_2dimage(C);
1026
1027         /* ortho at pixel level */
1028         UI_view2d_view_restore(C);
1029
1030         /* draw grease-pencil (screen aligned) */
1031         ED_gpencil_draw_view2d(C, 0);
1032 }
1033
1034 /* draws content borders plus safety borders if needed */
1035 static void sequencer_draw_borders(const SpaceSeq *sseq, const View2D *v2d, const Scene *scene)
1036 {
1037         float x1 = v2d->tot.xmin;
1038         float y1 = v2d->tot.ymin;
1039         float x2 = v2d->tot.xmax;
1040         float y2 = v2d->tot.ymax;
1041
1042         /* border */
1043         setlinestyle(3);
1044
1045         UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 1.0, 0);
1046
1047         glBegin(GL_LINE_LOOP);
1048         glVertex2f(x1 - 0.5f, y1 - 0.5f);
1049         glVertex2f(x1 - 0.5f, y2 + 0.5f);
1050         glVertex2f(x2 + 0.5f, y2 + 0.5f);
1051         glVertex2f(x2 + 0.5f, y1 - 0.5f);
1052         glEnd();
1053
1054         /* safety border */
1055         if (sseq->flag & SEQ_SHOW_SAFE_MARGINS) {
1056                 UI_draw_safe_areas(
1057                         x1, x2, y1, y2,
1058                         scene->safe_areas.title,
1059                         scene->safe_areas.action);
1060
1061                 if (sseq->flag & SEQ_SHOW_SAFE_CENTER) {
1062                         UI_draw_safe_areas(
1063                                 x1, x2, y1, y2,
1064                                 scene->safe_areas.title_center,
1065                                 scene->safe_areas.action_center);
1066                 }
1067         }
1068
1069         setlinestyle(0);
1070 }
1071
1072 /* draws checkerboard background for transparent content */
1073 static void sequencer_draw_background(const SpaceSeq *sseq, View2D *v2d, const float viewrect[2])
1074 {
1075         /* setting up the view */
1076         UI_view2d_totRect_set(v2d, viewrect[0] + 0.5f, viewrect[1] + 0.5f);
1077         UI_view2d_curRect_validate(v2d);
1078         UI_view2d_view_ortho(v2d);
1079
1080         /* only draw alpha for main buffer */
1081         if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1082                 if (sseq->flag & SEQ_USE_ALPHA) {
1083                         glEnable(GL_BLEND);
1084                         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1085
1086                         fdrawcheckerboard(v2d->tot.xmin, v2d->tot.ymin, v2d->tot.xmax, v2d->tot.ymax);
1087                         glColor4f(1.0, 1.0, 1.0, 1.0);
1088                 }
1089         }
1090 }
1091
1092 void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq, int cfra, int frame_ofs, bool draw_overlay, bool draw_backdrop)
1093 {
1094         struct Main *bmain = CTX_data_main(C);
1095         struct ImBuf *ibuf = NULL;
1096         struct ImBuf *scope = NULL;
1097         struct View2D *v2d = &ar->v2d;
1098         /* int rectx, recty; */ /* UNUSED */
1099         float viewrect[2];
1100         float col[3];
1101         GLuint texid;
1102         void *display_buffer;
1103         void *cache_handle = NULL;
1104         const bool is_imbuf = ED_space_sequencer_check_show_imbuf(sseq);
1105         int format, type;
1106         bool glsl_used = false;
1107         const bool draw_gpencil = ((sseq->flag & SEQ_SHOW_GPENCIL) && sseq->gpd);
1108         const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME};
1109         bool draw_metadata = false;
1110
1111         if (G.is_rendering == false && (scene->r.seq_flag & R_SEQ_GL_PREV) == 0) {
1112                 /* stop all running jobs, except screen one. currently previews frustrate Render
1113                  * needed to make so sequencer's rendering doesn't conflict with compositor
1114                  */
1115                 WM_jobs_kill_type(CTX_wm_manager(C), NULL, WM_JOB_TYPE_COMPOSITE);
1116
1117                 if ((scene->r.seq_flag & R_SEQ_GL_PREV) == 0) {
1118                         /* in case of final rendering used for preview, kill all previews,
1119                          * otherwise threading conflict will happen in rendering module
1120                          */
1121                         WM_jobs_kill_type(CTX_wm_manager(C), NULL, WM_JOB_TYPE_RENDER_PREVIEW);
1122                 }
1123         }
1124
1125         if ((!draw_overlay || sseq->overlay_type == SEQ_DRAW_OVERLAY_REFERENCE) && !draw_backdrop) {
1126                 UI_GetThemeColor3fv(TH_SEQ_PREVIEW, col);
1127                 glClearColor(col[0], col[1], col[2], 0.0);
1128                 glClear(GL_COLOR_BUFFER_BIT);
1129         }
1130
1131         /* without this colors can flicker from previous opengl state */
1132         glColor4ub(255, 255, 255, 255);
1133
1134         /* only initialize the preview if a render is in progress */
1135         if (G.is_rendering)
1136                 return;
1137
1138         if (sseq->render_size == SEQ_PROXY_RENDER_SIZE_NONE) {
1139                 return;
1140         }
1141
1142         /* for now we only support Left/Right */
1143         ibuf = sequencer_ibuf_get(bmain, scene, sseq, cfra, frame_ofs, names[sseq->multiview_eye]);
1144
1145         if ((ibuf == NULL) ||
1146             (ibuf->rect == NULL && ibuf->rect_float == NULL))
1147         {
1148                 /* gpencil can also be drawn without a valid imbuf */
1149                 if (draw_gpencil && is_imbuf) {
1150                         sequencer_display_size(scene, sseq, viewrect);
1151
1152                         sequencer_draw_background(sseq, v2d, viewrect);
1153                         sequencer_draw_borders(sseq, v2d, scene);
1154
1155                         sequencer_draw_gpencil(C);
1156                 }
1157                 return;
1158         }
1159
1160         sequencer_display_size(scene, sseq, viewrect);
1161
1162         if (!draw_backdrop && (sseq->mainb != SEQ_DRAW_IMG_IMBUF || sseq->zebra != 0)) {
1163                 SequencerScopes *scopes = &sseq->scopes;
1164
1165                 sequencer_check_scopes(scopes, ibuf);
1166
1167                 switch (sseq->mainb) {
1168                         case SEQ_DRAW_IMG_IMBUF:
1169                                 if (!scopes->zebra_ibuf) {
1170                                         ImBuf *display_ibuf = IMB_dupImBuf(ibuf);
1171
1172                                         if (display_ibuf->rect_float) {
1173                                                 IMB_colormanagement_imbuf_make_display_space(display_ibuf, &scene->view_settings,
1174                                                                                              &scene->display_settings);
1175                                         }
1176                                         scopes->zebra_ibuf = make_zebra_view_from_ibuf(display_ibuf, sseq->zebra);
1177                                         IMB_freeImBuf(display_ibuf);
1178                                 }
1179                                 scope = scopes->zebra_ibuf;
1180                                 break;
1181                         case SEQ_DRAW_IMG_WAVEFORM:
1182                                 if ((sseq->flag & SEQ_DRAW_COLOR_SEPARATED) != 0) {
1183                                         if (!scopes->sep_waveform_ibuf)
1184                                                 scopes->sep_waveform_ibuf = sequencer_make_scope(scene, ibuf, make_sep_waveform_view_from_ibuf);
1185                                         scope = scopes->sep_waveform_ibuf;
1186                                 }
1187                                 else {
1188                                         if (!scopes->waveform_ibuf)
1189                                                 scopes->waveform_ibuf = sequencer_make_scope(scene, ibuf, make_waveform_view_from_ibuf);
1190                                         scope = scopes->waveform_ibuf;
1191                                 }
1192                                 break;
1193                         case SEQ_DRAW_IMG_VECTORSCOPE:
1194                                 if (!scopes->vector_ibuf)
1195                                         scopes->vector_ibuf = sequencer_make_scope(scene, ibuf, make_vectorscope_view_from_ibuf);
1196                                 scope = scopes->vector_ibuf;
1197                                 break;
1198                         case SEQ_DRAW_IMG_HISTOGRAM:
1199                                 if (!scopes->histogram_ibuf)
1200                                         scopes->histogram_ibuf = sequencer_make_scope(scene, ibuf, make_histogram_view_from_ibuf);
1201                                 scope = scopes->histogram_ibuf;
1202                                 break;
1203                 }
1204
1205                 /* future files may have new scopes we don't catch above */
1206                 if (scope) {
1207                         scopes->reference_ibuf = ibuf;
1208                         if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1209                                 /* scopes drawn in image preview use viewrect from orig ibuf - currently that's only zebra */
1210                         }
1211                         else {
1212                                 viewrect[0] = scope->x;
1213                                 viewrect[1] = scope->y;
1214                         }
1215                 }
1216                 else {
1217                         scopes->reference_ibuf = NULL;
1218                 }
1219         }
1220
1221         if (!draw_backdrop) {
1222                 sequencer_draw_background(sseq, v2d, viewrect);
1223         }
1224
1225         if (scope) {
1226                 IMB_freeImBuf(ibuf);
1227                 ibuf = scope;
1228
1229                 if (ibuf->rect_float && ibuf->rect == NULL) {
1230                         IMB_rect_from_float(ibuf);
1231                 }
1232
1233                 display_buffer = (unsigned char *)ibuf->rect;
1234                 format = GL_RGBA;
1235                 type = GL_UNSIGNED_BYTE;
1236         }
1237         else {
1238                 bool force_fallback = false;
1239
1240                 force_fallback |= (U.image_draw_method != IMAGE_DRAW_METHOD_GLSL);
1241                 force_fallback |= (ibuf->dither != 0.0f);
1242
1243                 if (force_fallback) {
1244                         /* Fallback to CPU based color space conversion */
1245                         glsl_used = false;
1246                         format = GL_RGBA;
1247                         type = GL_UNSIGNED_BYTE;
1248                         display_buffer = NULL;
1249                 }
1250                 else if (ibuf->rect_float) {
1251                         display_buffer = ibuf->rect_float;
1252
1253                         if (ibuf->channels == 4) {
1254                                 format = GL_RGBA;
1255                         }
1256                         else if (ibuf->channels == 3) {
1257                                 format = GL_RGB;
1258                         }
1259                         else {
1260                                 BLI_assert(!"Incompatible number of channels for float buffer in sequencer");
1261                                 format = GL_RGBA;
1262                                 display_buffer = NULL;
1263                         }
1264
1265                         type = GL_FLOAT;
1266
1267                         if (ibuf->float_colorspace) {
1268                                 glsl_used = IMB_colormanagement_setup_glsl_draw_from_space_ctx(C, ibuf->float_colorspace, ibuf->dither, true);
1269                         }
1270                         else {
1271                                 glsl_used = IMB_colormanagement_setup_glsl_draw_ctx(C, ibuf->dither, true);
1272                         }
1273                 }
1274                 else if (ibuf->rect) {
1275                         display_buffer = ibuf->rect;
1276                         format = GL_RGBA;
1277                         type = GL_UNSIGNED_BYTE;
1278
1279                         glsl_used = IMB_colormanagement_setup_glsl_draw_from_space_ctx(C, ibuf->rect_colorspace, ibuf->dither, false);
1280                 }
1281                 else {
1282                         format = GL_RGBA;
1283                         type = GL_UNSIGNED_BYTE;
1284                         display_buffer = NULL;
1285                 }
1286
1287                 /* there's a data to be displayed, but GLSL is not initialized
1288                  * properly, in this case we fallback to CPU-based display transform
1289                  */
1290                 if ((ibuf->rect || ibuf->rect_float) && !glsl_used) {
1291                         display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle);
1292                         format = GL_RGBA;
1293                         type = GL_UNSIGNED_BYTE;
1294                 }
1295         }
1296
1297         glColor4f(1.0, 1.0, 1.0, 1.0);
1298
1299         GPU_simple_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR);
1300         glGenTextures(1, (GLuint *)&texid);
1301
1302         glBindTexture(GL_TEXTURE_2D, texid);
1303
1304         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1305         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1306
1307         if (type == GL_FLOAT)
1308                 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, ibuf->x, ibuf->y, 0, format, type, display_buffer);
1309         else
1310                 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ibuf->x, ibuf->y, 0, format, type, display_buffer);
1311
1312         if (draw_backdrop) {
1313                 glMatrixMode(GL_PROJECTION);
1314                 glPushMatrix();
1315                 glLoadIdentity();
1316                 glMatrixMode(GL_MODELVIEW);
1317                 glPushMatrix();
1318                 glLoadIdentity();
1319         }
1320         glBegin(GL_QUADS);
1321
1322         if (draw_overlay) {
1323                 if (sseq->overlay_type == SEQ_DRAW_OVERLAY_RECT) {
1324                         rctf tot_clip;
1325                         tot_clip.xmin = v2d->tot.xmin + (fabsf(BLI_rctf_size_x(&v2d->tot)) * scene->ed->over_border.xmin);
1326                         tot_clip.ymin = v2d->tot.ymin + (fabsf(BLI_rctf_size_y(&v2d->tot)) * scene->ed->over_border.ymin);
1327                         tot_clip.xmax = v2d->tot.xmin + (fabsf(BLI_rctf_size_x(&v2d->tot)) * scene->ed->over_border.xmax);
1328                         tot_clip.ymax = v2d->tot.ymin + (fabsf(BLI_rctf_size_y(&v2d->tot)) * scene->ed->over_border.ymax);
1329
1330                         glTexCoord2f(scene->ed->over_border.xmin, scene->ed->over_border.ymin); glVertex2f(tot_clip.xmin, tot_clip.ymin);
1331                         glTexCoord2f(scene->ed->over_border.xmin, scene->ed->over_border.ymax); glVertex2f(tot_clip.xmin, tot_clip.ymax);
1332                         glTexCoord2f(scene->ed->over_border.xmax, scene->ed->over_border.ymax); glVertex2f(tot_clip.xmax, tot_clip.ymax);
1333                         glTexCoord2f(scene->ed->over_border.xmax, scene->ed->over_border.ymin); glVertex2f(tot_clip.xmax, tot_clip.ymin);
1334                 }
1335                 else if (sseq->overlay_type == SEQ_DRAW_OVERLAY_REFERENCE) {
1336                         glTexCoord2f(0.0f, 0.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymin);
1337                         glTexCoord2f(0.0f, 1.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymax);
1338                         glTexCoord2f(1.0f, 1.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymax);
1339                         glTexCoord2f(1.0f, 0.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymin);
1340                 }
1341         }
1342         else if (draw_backdrop) {
1343                 float aspect;
1344                 float image_aspect = viewrect[0] / viewrect[1];
1345                 float imagex, imagey;
1346
1347                 aspect = BLI_rcti_size_x(&ar->winrct) / (float)BLI_rcti_size_y(&ar->winrct);
1348
1349                 if (aspect >= image_aspect) {
1350                         imagex = image_aspect / aspect;
1351                         imagey = 1.0f;
1352                 }
1353                 else {
1354                         imagex = 1.0f;
1355                         imagey = aspect / image_aspect;
1356                 }
1357
1358                 glTexCoord2f(0.0f, 0.0f); glVertex2f(-imagex, -imagey);
1359                 glTexCoord2f(0.0f, 1.0f); glVertex2f(-imagex, imagey);
1360                 glTexCoord2f(1.0f, 1.0f); glVertex2f(imagex, imagey);
1361                 glTexCoord2f(1.0f, 0.0f); glVertex2f(imagex, -imagey);
1362         }
1363         else {
1364                 draw_metadata = ((sseq->flag & SEQ_SHOW_METADATA) != 0);
1365
1366                 glTexCoord2f(0.0f, 0.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymin);
1367                 glTexCoord2f(0.0f, 1.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymax);
1368                 glTexCoord2f(1.0f, 1.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymax);
1369                 glTexCoord2f(1.0f, 0.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymin);
1370         }
1371         glEnd();
1372
1373         glBindTexture(GL_TEXTURE_2D, 0);
1374         GPU_simple_shader_bind(GPU_SHADER_USE_COLOR);
1375         if (sseq->mainb == SEQ_DRAW_IMG_IMBUF && sseq->flag & SEQ_USE_ALPHA)
1376                 glDisable(GL_BLEND);
1377         glDeleteTextures(1, &texid);
1378
1379         if (glsl_used)
1380                 IMB_colormanagement_finish_glsl_draw();
1381
1382         if (cache_handle)
1383                 IMB_display_buffer_release(cache_handle);
1384
1385         if (!scope)
1386                 IMB_freeImBuf(ibuf);
1387
1388         if (draw_metadata) {
1389                 ED_region_image_metadata_draw(0.0, 0.0, ibuf, &v2d->tot, 1.0, 1.0);
1390         }
1391
1392         if (draw_backdrop) {
1393                 glPopMatrix();
1394                 glMatrixMode(GL_PROJECTION);
1395                 glPopMatrix();
1396                 glMatrixMode(GL_MODELVIEW);
1397                 return;
1398         }
1399
1400         if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1401                 sequencer_draw_borders(sseq, v2d, scene);
1402         }
1403
1404         if (draw_gpencil && is_imbuf) {
1405                 sequencer_draw_gpencil(C);
1406         }
1407         else {
1408                 /* ortho at pixel level */
1409                 UI_view2d_view_restore(C);
1410         }
1411
1412
1413         /* NOTE: sequencer mask editing isnt finished, the draw code is working but editing not,
1414          * for now just disable drawing since the strip frame will likely be offset */
1415
1416         //if (sc->mode == SC_MODE_MASKEDIT) {
1417         if (0 && sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1418                 Mask *mask = BKE_sequencer_mask_get(scene);
1419
1420                 if (mask) {
1421                         int width, height;
1422                         float aspx = 1.0f, aspy = 1.0f;
1423                         // ED_mask_get_size(C, &width, &height);
1424
1425                         //Scene *scene = CTX_data_scene(C);
1426                         width = (scene->r.size * scene->r.xsch) / 100;
1427                         height = (scene->r.size * scene->r.ysch) / 100;
1428
1429                         ED_mask_draw_region(mask, ar,
1430                                             0, 0, 0,  /* TODO */
1431                                             width, height,
1432                                             aspx, aspy,
1433                                             false, true,
1434                                             NULL, C);
1435                 }
1436         }
1437 }
1438
1439 #if 0
1440 void drawprefetchseqspace(Scene *scene, ARegion *UNUSED(ar), SpaceSeq *sseq)
1441 {
1442         int rectx, recty;
1443         int render_size = sseq->render_size;
1444         int proxy_size = 100.0; 
1445         if (render_size == 0) {
1446                 render_size = scene->r.size;
1447         }
1448         else {
1449                 proxy_size = render_size;
1450         }
1451         if (render_size < 0) {
1452                 return;
1453         }
1454
1455         rectx = (render_size * scene->r.xsch) / 100;
1456         recty = (render_size * scene->r.ysch) / 100;
1457
1458         if (sseq->mainb != SEQ_DRAW_SEQUENCE) {
1459                 give_ibuf_prefetch_request(
1460                     rectx, recty, (scene->r.cfra), sseq->chanshown,
1461                     proxy_size);
1462         }
1463 }
1464 #endif
1465
1466 /* draw backdrop of the sequencer strips view */
1467 static void draw_seq_backdrop(View2D *v2d)
1468 {
1469         int i;
1470         
1471         /* darker gray overlay over the view backdrop */
1472         UI_ThemeColorShade(TH_BACK, -20);
1473         glRectf(v2d->cur.xmin,  -1.0,  v2d->cur.xmax,  1.0);
1474
1475         /* Alternating horizontal stripes */
1476         i = max_ii(1, ((int)v2d->cur.ymin) - 1);
1477
1478         glBegin(GL_QUADS);
1479         while (i < v2d->cur.ymax) {
1480                 if (((int)i) & 1)
1481                         UI_ThemeColorShade(TH_BACK, -15);
1482                 else
1483                         UI_ThemeColorShade(TH_BACK, -25);
1484                         
1485                 glVertex2f(v2d->cur.xmax, i);
1486                 glVertex2f(v2d->cur.xmin, i);
1487                 glVertex2f(v2d->cur.xmin, i + 1);
1488                 glVertex2f(v2d->cur.xmax, i + 1);
1489
1490                 i += 1.0;
1491         }
1492         glEnd();
1493         
1494         /* Darker lines separating the horizontal bands */
1495         i = max_ii(1, ((int)v2d->cur.ymin) - 1);
1496         UI_ThemeColor(TH_GRID);
1497         
1498         glBegin(GL_LINES);
1499         while (i < v2d->cur.ymax) {
1500                 glVertex2f(v2d->cur.xmax, i);
1501                 glVertex2f(v2d->cur.xmin, i);
1502                         
1503                 i += 1.0;
1504         }
1505         glEnd();
1506 }
1507
1508 /* draw the contents of the sequencer strips view */
1509 static void draw_seq_strips(const bContext *C, Editing *ed, ARegion *ar)
1510 {
1511         Scene *scene = CTX_data_scene(C);
1512         View2D *v2d = &ar->v2d;
1513         SpaceSeq *sseq = CTX_wm_space_seq(C);
1514         Sequence *last_seq = BKE_sequencer_active_get(scene);
1515         int sel = 0, j;
1516         float pixelx = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask);
1517         
1518         /* loop through twice, first unselected, then selected */
1519         for (j = 0; j < 2; j++) {
1520                 Sequence *seq;
1521                 int outline_tint = (j) ? -60 : -150; /* highlighting around strip edges indicating selection */
1522                 
1523                 /* loop through strips, checking for those that are visible */
1524                 for (seq = ed->seqbasep->first; seq; seq = seq->next) {
1525                         /* boundbox and selection tests for NOT drawing the strip... */
1526                         if ((seq->flag & SELECT) != sel) continue;
1527                         else if (seq == last_seq) continue;
1528                         else if (min_ii(seq->startdisp, seq->start) > v2d->cur.xmax) continue;
1529                         else if (max_ii(seq->enddisp, seq->start + seq->len) < v2d->cur.xmin) continue;
1530                         else if (seq->machine + 1.0f < v2d->cur.ymin) continue;
1531                         else if (seq->machine > v2d->cur.ymax) continue;
1532                         
1533                         /* strip passed all tests unscathed... so draw it now */
1534                         draw_seq_strip(C, sseq, scene, ar, seq, outline_tint, pixelx);
1535                 }
1536                 
1537                 /* draw selected next time round */
1538                 sel = SELECT;
1539         }
1540         
1541         /* draw the last selected last (i.e. 'active' in other parts of Blender), removes some overlapping error */
1542         if (last_seq)
1543                 draw_seq_strip(C, sseq, scene, ar, last_seq, 120, pixelx);
1544
1545         /* draw highlight when previewing a single strip */
1546         if (special_seq_update) {
1547                 const Sequence *seq = special_seq_update;
1548                 glEnable(GL_BLEND);
1549                 glColor4ub(255, 255, 255, 48);
1550                 glRectf(seq->startdisp, seq->machine + SEQ_STRIP_OFSBOTTOM, seq->enddisp, seq->machine + SEQ_STRIP_OFSTOP);
1551                 glDisable(GL_BLEND);
1552         }
1553 }
1554
1555 static void seq_draw_sfra_efra(Scene *scene, View2D *v2d)
1556 {
1557         const Editing *ed = BKE_sequencer_editing_get(scene, false);
1558         const int frame_sta = PSFRA;
1559         const int frame_end = PEFRA + 1;
1560
1561         glEnable(GL_BLEND);
1562         
1563         /* draw darkened area outside of active timeline 
1564          * frame range used is preview range or scene range */
1565         UI_ThemeColorShadeAlpha(TH_BACK, -25, -100);
1566
1567         if (frame_sta < frame_end) {
1568                 glRectf(v2d->cur.xmin, v2d->cur.ymin, (float)frame_sta, v2d->cur.ymax);
1569                 glRectf((float)frame_end, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
1570         }
1571         else {
1572                 glRectf(v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
1573         }
1574
1575         UI_ThemeColorShade(TH_BACK, -60);
1576         /* thin lines where the actual frames are */
1577         fdrawline(frame_sta, v2d->cur.ymin, frame_sta, v2d->cur.ymax);
1578         fdrawline(frame_end, v2d->cur.ymin, frame_end, v2d->cur.ymax);
1579
1580         if (ed && !BLI_listbase_is_empty(&ed->metastack)) {
1581                 MetaStack *ms = ed->metastack.last;
1582
1583                 glColor4ub(255, 255, 255, 8);
1584                 glRectf(ms->disp_range[0], v2d->cur.ymin, ms->disp_range[1], v2d->cur.ymax);
1585
1586                 UI_ThemeColorShade(TH_BACK, -40);
1587
1588                 fdrawline(ms->disp_range[0], v2d->cur.ymin, ms->disp_range[0], v2d->cur.ymax);
1589                 fdrawline(ms->disp_range[1], v2d->cur.ymin, ms->disp_range[1], v2d->cur.ymax);
1590         }
1591
1592         glDisable(GL_BLEND);
1593 }
1594
1595 /* Draw Timeline/Strip Editor Mode for Sequencer */
1596 void draw_timeline_seq(const bContext *C, ARegion *ar)
1597 {
1598         Scene *scene = CTX_data_scene(C);
1599         Editing *ed = BKE_sequencer_editing_get(scene, false);
1600         SpaceSeq *sseq = CTX_wm_space_seq(C);
1601         View2D *v2d = &ar->v2d;
1602         View2DScrollers *scrollers;
1603         short unit = 0, flag = 0;
1604         float col[3];
1605         
1606         /* clear and setup matrix */
1607         UI_GetThemeColor3fv(TH_BACK, col);
1608         if (ed && ed->metastack.first) 
1609                 glClearColor(col[0], col[1], col[2] - 0.1f, 0.0f);
1610         else 
1611                 glClearColor(col[0], col[1], col[2], 0.0f);
1612         glClear(GL_COLOR_BUFFER_BIT);
1613
1614         UI_view2d_view_ortho(v2d);
1615         
1616         
1617         /* calculate extents of sequencer strips/data 
1618          * NOTE: needed for the scrollers later
1619          */
1620         boundbox_seq(scene, &v2d->tot);
1621         
1622         
1623         /* draw backdrop */
1624         draw_seq_backdrop(v2d);
1625         
1626         /* regular grid-pattern over the rest of the view (i.e. 25-frame grid lines) */
1627         // NOTE: the gridlines are currently spaced every 25 frames, which is only fine for 25 fps, but maybe not for 30...
1628         UI_view2d_constant_grid_draw(v2d);
1629
1630         if (sseq->draw_flag & SEQ_DRAW_BACKDROP) {
1631                 draw_image_seq(C, scene, ar, sseq, scene->r.cfra, 0, false, true);
1632                 UI_view2d_view_ortho(v2d);
1633         }
1634                 
1635         ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
1636         
1637         seq_draw_sfra_efra(scene, v2d);
1638
1639         /* sequence strips (if there is data available to be drawn) */
1640         if (ed) {
1641                 /* draw the data */
1642                 draw_seq_strips(C, ed, ar);
1643                 
1644                 /* text draw cached (for sequence names), in pixelspace now */
1645                 UI_view2d_text_cache_draw(ar);
1646         }
1647         
1648         /* current frame */
1649         UI_view2d_view_ortho(v2d);
1650         if ((sseq->flag & SEQ_DRAWFRAMES) == 0)      flag |= DRAWCFRA_UNIT_SECONDS;
1651         if ((sseq->flag & SEQ_NO_DRAW_CFRANUM) == 0) flag |= DRAWCFRA_SHOW_NUMBOX;
1652         ANIM_draw_cfra(C, v2d, flag);
1653         
1654         /* markers */
1655         UI_view2d_view_orthoSpecial(ar, v2d, 1);
1656         ED_markers_draw(C, DRAW_MARKERS_LINES | DRAW_MARKERS_MARGIN);
1657         
1658         /* preview range */
1659         UI_view2d_view_ortho(v2d);
1660         ANIM_draw_previewrange(C, v2d, 1);
1661
1662         /* overlap playhead */
1663         if (scene->ed && scene->ed->over_flag & SEQ_EDIT_OVERLAY_SHOW) {
1664                 int cfra_over = (scene->ed->over_flag & SEQ_EDIT_OVERLAY_ABS) ? scene->ed->over_cfra : scene->r.cfra + scene->ed->over_ofs;
1665                 glColor3f(0.2, 0.2, 0.2);
1666                 // glRectf(cfra_over, v2d->cur.ymin, scene->ed->over_ofs + scene->r.cfra + 1, v2d->cur.ymax);
1667
1668                 glBegin(GL_LINES);
1669                 glVertex2f(cfra_over, v2d->cur.ymin);
1670                 glVertex2f(cfra_over, v2d->cur.ymax);
1671                 glEnd();
1672
1673         }
1674         
1675         /* callback */
1676         ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
1677
1678         /* reset view matrix */
1679         UI_view2d_view_restore(C);
1680
1681         /* scrollers */
1682         unit = (sseq->flag & SEQ_DRAWFRAMES) ? V2D_UNIT_FRAMES : V2D_UNIT_SECONDS;
1683         scrollers = UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_UNIT_VALUES, V2D_GRID_CLAMP);
1684         UI_view2d_scrollers_draw(C, v2d, scrollers);
1685         UI_view2d_scrollers_free(scrollers);
1686 }
1687
1688