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