2 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * Contributor(s): Blender Foundation, 2003-2009
23 * ***** END GPL LICENSE BLOCK *****
26 /** \file blender/editors/space_sequencer/sequencer_draw.c
34 #include "BLI_blenlib.h"
36 #include "BLI_utildefines.h"
37 #include "BLI_threads.h"
39 #include "IMB_imbuf_types.h"
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"
48 #include "BKE_context.h"
49 #include "BKE_global.h"
51 #include "BKE_sequencer.h"
52 #include "BKE_sound.h"
53 #include "BKE_scene.h"
55 #include "IMB_colormanagement.h"
56 #include "IMB_imbuf.h"
59 #include "BIF_glutil.h"
61 #include "ED_anim_api.h"
62 #include "ED_gpencil.h"
63 #include "ED_markers.h"
65 #include "ED_sequencer.h"
66 #include "ED_space_api.h"
68 #include "UI_interface.h"
69 #include "UI_resources.h"
70 #include "UI_view2d.h"
74 #include "MEM_guardedalloc.h"
77 #include "sequencer_intern.h"
80 #define SEQ_LEFTHANDLE 1
81 #define SEQ_RIGHTHANDLE 2
83 #define SEQ_HANDLE_SIZE_MIN 7.0f
84 #define SEQ_HANDLE_SIZE_MAX 40.0f
87 /* Note, Don't use SEQ_BEGIN/SEQ_END while drawing!
88 * it messes up transform, - Campbell */
93 static Sequence *special_seq_update = NULL;
95 void color3ubv_from_seq(Scene *curscene, Sequence *seq, unsigned char col[3])
97 unsigned char blendcol[3];
98 SolidColorVars *colvars = (SolidColorVars *)seq->effectdata;
102 UI_GetThemeColor3ubv(TH_SEQ_IMAGE, col);
106 UI_GetThemeColor3ubv(TH_SEQ_META, col);
110 UI_GetThemeColor3ubv(TH_SEQ_MOVIE, col);
113 case SEQ_TYPE_MOVIECLIP:
114 UI_GetThemeColor3ubv(TH_SEQ_MOVIECLIP, col);
118 UI_GetThemeColor3ubv(TH_SEQ_MASK, col); /* TODO */
122 UI_GetThemeColor3ubv(TH_SEQ_SCENE, col);
124 if (seq->scene == curscene) {
125 UI_GetColorPtrShade3ubv(col, col, 20);
131 case SEQ_TYPE_GAMCROSS:
133 UI_GetThemeColor3ubv(TH_SEQ_TRANSITION, col);
135 /* slightly offset hue to distinguish different effects */
136 if (seq->type == SEQ_TYPE_CROSS) rgb_byte_set_hue_float_offset(col, 0.04);
137 if (seq->type == SEQ_TYPE_GAMCROSS) rgb_byte_set_hue_float_offset(col, 0.08);
138 if (seq->type == SEQ_TYPE_WIPE) rgb_byte_set_hue_float_offset(col, 0.12);
142 case SEQ_TYPE_TRANSFORM:
147 case SEQ_TYPE_ALPHAOVER:
148 case SEQ_TYPE_ALPHAUNDER:
149 case SEQ_TYPE_OVERDROP:
151 case SEQ_TYPE_MULTICAM:
152 case SEQ_TYPE_ADJUSTMENT:
153 case SEQ_TYPE_GAUSSIAN_BLUR:
154 UI_GetThemeColor3ubv(TH_SEQ_EFFECT, col);
156 /* slightly offset hue to distinguish different effects */
157 if (seq->type == SEQ_TYPE_ADD) rgb_byte_set_hue_float_offset(col, 0.04);
158 else if (seq->type == SEQ_TYPE_SUB) rgb_byte_set_hue_float_offset(col, 0.08);
159 else if (seq->type == SEQ_TYPE_MUL) rgb_byte_set_hue_float_offset(col, 0.12);
160 else if (seq->type == SEQ_TYPE_ALPHAOVER) rgb_byte_set_hue_float_offset(col, 0.16);
161 else if (seq->type == SEQ_TYPE_ALPHAUNDER) rgb_byte_set_hue_float_offset(col, 0.20);
162 else if (seq->type == SEQ_TYPE_OVERDROP) rgb_byte_set_hue_float_offset(col, 0.24);
163 else if (seq->type == SEQ_TYPE_GLOW) rgb_byte_set_hue_float_offset(col, 0.28);
164 else if (seq->type == SEQ_TYPE_TRANSFORM) rgb_byte_set_hue_float_offset(col, 0.36);
165 else if (seq->type == SEQ_TYPE_MULTICAM) rgb_byte_set_hue_float_offset(col, 0.32);
166 else if (seq->type == SEQ_TYPE_ADJUSTMENT) rgb_byte_set_hue_float_offset(col, 0.40);
167 else if (seq->type == SEQ_TYPE_GAUSSIAN_BLUR) rgb_byte_set_hue_float_offset(col, 0.42);
171 rgb_float_to_uchar(col, colvars->col);
174 case SEQ_TYPE_SOUND_RAM:
175 UI_GetThemeColor3ubv(TH_SEQ_AUDIO, col);
176 blendcol[0] = blendcol[1] = blendcol[2] = 128;
177 if (seq->flag & SEQ_MUTE) UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.5, 20);
181 col[0] = 10; col[1] = 255; col[2] = 40;
186 static void drawseqwave(const bContext *C, SpaceSeq *sseq, Scene *scene, Sequence *seq, float x1, float y1, float x2, float y2, float stepsize)
189 * x1 is the starting x value to draw the wave,
190 * x2 the end x value, same for y1 and y2
191 * stepsize is width of a pixel.
193 if ((sseq->flag & SEQ_ALL_WAVEFORMS) || (seq->flag & SEQ_AUDIO_DRAW_WAVEFORM)) {
195 int length = floor((x2 - x1) / stepsize) + 1;
196 float ymid = (y1 + y2) / 2;
197 float yscale = (y2 - y1) / 2;
199 float startsample, endsample;
201 bSound *sound = seq->sound;
203 SoundWaveform *waveform;
205 if (!sound->spinlock) {
206 sound->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock");
207 BLI_spin_init(sound->spinlock);
210 BLI_spin_lock(sound->spinlock);
211 if (!seq->sound->waveform) {
212 if (!(sound->flags & SOUND_FLAGS_WAVEFORM_LOADING)) {
213 /* prevent sounds from reloading */
214 seq->sound->flags |= SOUND_FLAGS_WAVEFORM_LOADING;
215 BLI_spin_unlock(sound->spinlock);
216 sequencer_preview_add_sound(C, seq);
219 BLI_spin_unlock(sound->spinlock);
221 return; /* nothing to draw */
223 BLI_spin_unlock(sound->spinlock);
225 waveform = seq->sound->waveform;
227 startsample = floor((seq->startofs + seq->anim_startofs) / FPS * SOUND_WAVE_SAMPLES_PER_SECOND);
228 endsample = ceil((seq->startofs + seq->anim_startofs + seq->enddisp - seq->startdisp) / FPS * SOUND_WAVE_SAMPLES_PER_SECOND);
229 samplestep = (endsample - startsample) * stepsize / (x2 - x1);
231 if (length > floor((waveform->length - startsample) / samplestep))
232 length = floor((waveform->length - startsample) / samplestep);
234 glBegin(GL_LINE_STRIP);
235 for (i = 0; i < length; i++) {
236 pos = startsample + i * samplestep;
238 value = waveform->data[pos * 3];
240 for (j = pos + 1; (j < waveform->length) && (j < pos + samplestep); j++) {
241 if (value > waveform->data[j * 3])
242 value = waveform->data[j * 3];
245 glVertex2f(x1 + i * stepsize, ymid + value * yscale);
249 glBegin(GL_LINE_STRIP);
250 for (i = 0; i < length; i++) {
251 pos = startsample + i * samplestep;
253 value = waveform->data[pos * 3 + 1];
255 for (j = pos + 1; (j < waveform->length) && (j < pos + samplestep); j++) {
256 if (value < waveform->data[j * 3 + 1])
257 value = waveform->data[j * 3 + 1];
260 glVertex2f(x1 + i * stepsize, ymid + value * yscale);
266 static void drawmeta_stipple(int value)
269 glEnable(GL_POLYGON_STIPPLE);
270 glPolygonStipple(stipple_halftone);
272 glEnable(GL_LINE_STIPPLE);
273 glLineStipple(1, 0x8888);
276 glDisable(GL_POLYGON_STIPPLE);
277 glDisable(GL_LINE_STIPPLE);
281 static void drawmeta_contents(Scene *scene, Sequence *seqm, float x1, float y1, float x2, float y2)
283 /* note: this used to use SEQ_BEGIN/SEQ_END, but it messes up the
284 * seq->depth value, (needed by transform when doing overlap checks)
285 * so for now, just use the meta's immediate children, could be fixed but
286 * its only drawing - campbell */
288 unsigned char col[4];
290 int chan_min = MAXSEQ;
293 float draw_range = y2 - y1;
297 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
299 if (seqm->flag & SEQ_MUTE)
302 for (seq = seqm->seqbase.first; seq; seq = seq->next) {
303 chan_min = min_ii(chan_min, seq->machine);
304 chan_max = max_ii(chan_max, seq->machine);
307 chan_range = (chan_max - chan_min) + 1;
308 draw_height = draw_range / chan_range;
310 col[3] = 196; /* alpha, used for all meta children */
312 for (seq = seqm->seqbase.first; seq; seq = seq->next) {
313 if ((seq->startdisp > x2 || seq->enddisp < x1) == 0) {
314 float y_chan = (seq->machine - chan_min) / (float)(chan_range) * draw_range;
315 float x1_chan = seq->startdisp;
316 float x2_chan = seq->enddisp;
317 float y1_chan, y2_chan;
319 if ((seqm->flag & SEQ_MUTE) == 0 && (seq->flag & SEQ_MUTE))
322 color3ubv_from_seq(scene, seq, col);
326 /* clamp within parent sequence strip bounds */
327 if (x1_chan < x1) x1_chan = x1;
328 if (x2_chan > x2) x2_chan = x2;
330 y1_chan = y1 + y_chan + (draw_height * SEQ_STRIP_OFSBOTTOM);
331 y2_chan = y1 + y_chan + (draw_height * SEQ_STRIP_OFSTOP);
333 glRectf(x1_chan, y1_chan, x2_chan, y2_chan);
335 UI_GetColorPtrShade3ubv(col, col, -30);
337 fdrawbox(x1_chan, y1_chan, x2_chan, y2_chan);
339 if ((seqm->flag & SEQ_MUTE) == 0 && (seq->flag & SEQ_MUTE))
344 if (seqm->flag & SEQ_MUTE)
350 /* clamp handles to defined size in pixel space */
351 static float draw_seq_handle_size_get_clamped(Sequence *seq, const float pixelx)
353 const float minhandle = pixelx * SEQ_HANDLE_SIZE_MIN;
354 const float maxhandle = pixelx * SEQ_HANDLE_SIZE_MAX;
355 float size = CLAMPIS(seq->handsize, minhandle, maxhandle);
357 /* ensure we're not greater than half width */
358 return min_ff(size, ((float)(seq->enddisp - seq->startdisp) / 2.0f) / pixelx);
361 /* draw a handle, for each end of a sequence strip */
362 static void draw_seq_handle(View2D *v2d, Sequence *seq, const float handsize_clamped, const short direction)
364 float v1[2], v2[2], v3[2], rx1 = 0, rx2 = 0; //for triangles and rect
365 float x1, x2, y1, y2;
366 unsigned int whichsel = 0;
371 y1 = seq->machine + SEQ_STRIP_OFSBOTTOM;
372 y2 = seq->machine + SEQ_STRIP_OFSTOP;
374 /* set up co-ordinates/dimensions for either left or right handle */
375 if (direction == SEQ_LEFTHANDLE) {
377 rx2 = x1 + handsize_clamped * 0.75f;
379 v1[0] = x1 + handsize_clamped / 4; v1[1] = y1 + ( ((y1 + y2) / 2.0f - y1) / 2);
380 v2[0] = x1 + handsize_clamped / 4; v2[1] = y2 - ( ((y1 + y2) / 2.0f - y1) / 2);
381 v3[0] = v2[0] + handsize_clamped / 4; v3[1] = (y1 + y2) / 2.0f;
383 whichsel = SEQ_LEFTSEL;
385 else if (direction == SEQ_RIGHTHANDLE) {
386 rx1 = x2 - handsize_clamped * 0.75f;
389 v1[0] = x2 - handsize_clamped / 4; v1[1] = y1 + ( ((y1 + y2) / 2.0f - y1) / 2);
390 v2[0] = x2 - handsize_clamped / 4; v2[1] = y2 - ( ((y1 + y2) / 2.0f - y1) / 2);
391 v3[0] = v2[0] - handsize_clamped / 4; v3[1] = (y1 + y2) / 2.0f;
393 whichsel = SEQ_RIGHTSEL;
397 if (seq->type < SEQ_TYPE_EFFECT ||
398 BKE_sequence_effect_get_num_inputs(seq->type) == 0)
402 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
404 if (seq->flag & whichsel) glColor4ub(0, 0, 0, 80);
405 else if (seq->flag & SELECT) glColor4ub(255, 255, 255, 30);
406 else glColor4ub(0, 0, 0, 22);
408 glRectf(rx1, y1, rx2, y2);
410 if (seq->flag & whichsel) glColor4ub(255, 255, 255, 200);
411 else glColor4ub(0, 0, 0, 50);
413 glEnable(GL_POLYGON_SMOOTH);
414 glBegin(GL_TRIANGLES);
415 glVertex2fv(v1); glVertex2fv(v2); glVertex2fv(v3);
418 glDisable(GL_POLYGON_SMOOTH);
422 if ((G.moving & G_TRANSFORM_SEQ) || (seq->flag & whichsel)) {
423 const char col[4] = {255, 255, 255, 255};
427 if (direction == SEQ_LEFTHANDLE) {
428 numstr_len = BLI_snprintf(numstr, sizeof(numstr), "%d", seq->startdisp);
433 numstr_len = BLI_snprintf(numstr, sizeof(numstr), "%d", seq->enddisp - 1);
434 x1 = x2 - handsize_clamped * 0.75f;
437 UI_view2d_text_cache_add(v2d, x1, y1, numstr, numstr_len, col);
441 /* draw info text on a sequence strip */
442 static void draw_seq_text(View2D *v2d, Sequence *seq, float x1, float x2, float y1, float y2, const unsigned char background_col[3])
445 char str[32 + FILE_MAX];
447 const char *name = seq->name + 2;
450 /* note, all strings should include 'name' */
452 name = BKE_sequence_give_name(seq);
454 if (seq->type == SEQ_TYPE_META || seq->type == SEQ_TYPE_ADJUSTMENT) {
455 str_len = BLI_snprintf(str, sizeof(str), "%s | %d", name, seq->len);
457 else if (seq->type == SEQ_TYPE_SCENE) {
459 if (seq->scene_camera) {
460 str_len = BLI_snprintf(str, sizeof(str), "%s: %s (%s) | %d",
461 name, seq->scene->id.name + 2, ((ID *)seq->scene_camera)->name + 2, seq->len);
464 str_len = BLI_snprintf(str, sizeof(str), "%s: %s | %d",
465 name, seq->scene->id.name + 2, seq->len);
469 str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
473 else if (seq->type == SEQ_TYPE_MOVIECLIP) {
474 if (seq->clip && !STREQ(name, seq->clip->id.name + 2)) {
475 str_len = BLI_snprintf(str, sizeof(str), "%s: %s | %d",
476 name, seq->clip->id.name + 2, seq->len);
479 str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
483 else if (seq->type == SEQ_TYPE_MASK) {
484 if (seq->mask && !STREQ(name, seq->mask->id.name + 2)) {
485 str_len = BLI_snprintf(str, sizeof(str), "%s: %s | %d",
486 name, seq->mask->id.name + 2, seq->len);
489 str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
493 else if (seq->type == SEQ_TYPE_MULTICAM) {
494 str_len = BLI_snprintf(str, sizeof(str), "Cam %s: %d",
495 name, seq->multicam_source);
497 else if (seq->type == SEQ_TYPE_IMAGE) {
498 str_len = BLI_snprintf(str, sizeof(str), "%s: %s%s | %d",
499 name, seq->strip->dir, seq->strip->stripdata->name, seq->len);
501 else if (seq->type & SEQ_TYPE_EFFECT) {
502 str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
505 else if (seq->type == SEQ_TYPE_SOUND_RAM) {
507 str_len = BLI_snprintf(str, sizeof(str), "%s: %s | %d",
508 name, seq->sound->name, seq->len);
511 str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
515 else if (seq->type == SEQ_TYPE_MOVIE) {
516 str_len = BLI_snprintf(str, sizeof(str), "%s: %s%s | %d",
517 name, seq->strip->dir, seq->strip->stripdata->name, seq->len);
520 /* should never get here!, but might with files from future */
523 str_len = BLI_snprintf(str, sizeof(str), "%s | %d",
527 if (seq->flag & SELECT) {
528 col[0] = col[1] = col[2] = 255;
530 else if ((((int)background_col[0] + (int)background_col[1] + (int)background_col[2]) / 3) < 50) {
531 col[0] = col[1] = col[2] = 80; /* use lighter text color for dark background */
534 col[0] = col[1] = col[2] = 0;
543 UI_view2d_text_cache_add_rectf(v2d, &rect, str, str_len, col);
546 /* draws a shaded strip, made from gradient + flat color + gradient */
547 void draw_shadedstrip(Sequence *seq, unsigned char col[3], float x1, float y1, float x2, float y2)
551 if (seq->flag & SEQ_MUTE) {
552 glEnable(GL_POLYGON_STIPPLE);
553 glPolygonStipple(stipple_halftone);
556 ymid1 = (y2 - y1) * 0.25f + y1;
557 ymid2 = (y2 - y1) * 0.65f + y1;
559 glShadeModel(GL_SMOOTH);
562 if (seq->flag & SEQ_INVALID_EFFECT) { col[0] = 255; col[1] = 0; col[2] = 255; }
563 else if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, -50);
564 /* else UI_GetColorPtrShade3ubv(col, col, 0); */ /* DO NOTHING */
571 if (seq->flag & SEQ_INVALID_EFFECT) { col[0] = 255; col[1] = 0; col[2] = 255; }
572 else if (seq->flag & SELECT) UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, 5);
573 else UI_GetColorPtrShade3ubv(col, col, -5);
575 glColor3ubv((GLubyte *)col);
577 glVertex2f(x2, ymid1);
578 glVertex2f(x1, ymid1);
582 glRectf(x1, ymid1, x2, ymid2);
586 glVertex2f(x1, ymid2);
587 glVertex2f(x2, ymid2);
589 if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, -15);
590 else UI_GetColorPtrShade3ubv(col, col, 25);
592 glColor3ubv((GLubyte *)col);
599 if (seq->flag & SEQ_MUTE) {
600 glDisable(GL_POLYGON_STIPPLE);
604 void draw_sequence_extensions(Scene *scene, ARegion *ar, Sequence *seq)
606 float x1, x2, y1, y2, pixely, a;
607 unsigned char col[3], blendcol[3];
608 View2D *v2d = &ar->v2d;
613 y1 = seq->machine + SEQ_STRIP_OFSBOTTOM;
614 y2 = seq->machine + SEQ_STRIP_OFSTOP;
616 pixely = BLI_rctf_size_y(&v2d->cur) / BLI_rcti_size_y(&v2d->mask);
618 if (pixely <= 0) return; /* can happen when the view is split/resized */
620 blendcol[0] = blendcol[1] = blendcol[2] = 120;
624 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
626 color3ubv_from_seq(scene, seq, col);
628 if (seq->flag & SELECT) {
629 UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.3, -40);
630 glColor4ub(col[0], col[1], col[2], 170);
633 UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.6, 0);
634 glColor4ub(col[0], col[1], col[2], 110);
637 glRectf((float)(seq->start), y1 - SEQ_STRIP_OFSBOTTOM, x1, y1);
639 if (seq->flag & SELECT) glColor4ub(col[0], col[1], col[2], 255);
640 else glColor4ub(col[0], col[1], col[2], 160);
642 fdrawbox((float)(seq->start), y1 - SEQ_STRIP_OFSBOTTOM, x1, y1); //outline
648 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
650 color3ubv_from_seq(scene, seq, col);
652 if (seq->flag & SELECT) {
653 UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.3, -40);
654 glColor4ub(col[0], col[1], col[2], 170);
657 UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.6, 0);
658 glColor4ub(col[0], col[1], col[2], 110);
661 glRectf(x2, y2, (float)(seq->start + seq->len), y2 + SEQ_STRIP_OFSBOTTOM);
663 if (seq->flag & SELECT) glColor4ub(col[0], col[1], col[2], 255);
664 else glColor4ub(col[0], col[1], col[2], 160);
666 fdrawbox(x2, y2, (float)(seq->start + seq->len), y2 + SEQ_STRIP_OFSBOTTOM); //outline
670 if (seq->startstill) {
671 color3ubv_from_seq(scene, seq, col);
672 UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.75, 40);
673 glColor3ubv((GLubyte *)col);
675 draw_shadedstrip(seq, col, x1, y1, (float)(seq->start), y2);
677 /* feint pinstripes, helps see exactly which is extended and which isn't,
678 * especially when the extension is very small */
679 if (seq->flag & SELECT) UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, 24);
680 else UI_GetColorPtrShade3ubv(col, col, -16);
682 glColor3ubv((GLubyte *)col);
684 for (a = y1; a < y2; a += pixely * 2.0f) {
685 fdrawline(x1, a, (float)(seq->start), a);
689 color3ubv_from_seq(scene, seq, col);
690 UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.75, 40);
691 glColor3ubv((GLubyte *)col);
693 draw_shadedstrip(seq, col, (float)(seq->start + seq->len), y1, x2, y2);
695 /* feint pinstripes, helps see exactly which is extended and which isn't,
696 * especially when the extension is very small */
697 if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, 24);
698 else UI_GetColorPtrShade3ubv(col, col, -16);
700 glColor3ubv((GLubyte *)col);
702 for (a = y1; a < y2; a += pixely * 2.0f) {
703 fdrawline((float)(seq->start + seq->len), a, x2, a);
710 * Draw a sequence strip, bounds check already made
711 * ARegion is currently only used to get the windows width in pixels
712 * so wave file sample drawing precision is zoom adjusted
714 static void draw_seq_strip(const bContext *C, SpaceSeq *sseq, Scene *scene, ARegion *ar, Sequence *seq, int outline_tint, float pixelx)
716 View2D *v2d = &ar->v2d;
717 float x1, x2, y1, y2;
718 unsigned char col[3], background_col[3], is_single_image;
719 const float handsize_clamped = draw_seq_handle_size_get_clamped(seq, pixelx);
721 /* we need to know if this is a single image/color or not for drawing */
722 is_single_image = (char)BKE_sequence_single_check(seq);
725 x1 = (seq->startstill) ? seq->start : seq->startdisp;
726 y1 = seq->machine + SEQ_STRIP_OFSBOTTOM;
727 x2 = (seq->endstill) ? (seq->start + seq->len) : seq->enddisp;
728 y2 = seq->machine + SEQ_STRIP_OFSTOP;
731 /* get the correct color per strip type*/
732 //color3ubv_from_seq(scene, seq, col);
733 color3ubv_from_seq(scene, seq, background_col);
735 /* draw the main strip body */
736 if (is_single_image) { /* single image */
737 draw_shadedstrip(seq, background_col,
738 BKE_sequence_tx_get_final_left(seq, false), y1,
739 BKE_sequence_tx_get_final_right(seq, false), y2);
741 else { /* normal operation */
742 draw_shadedstrip(seq, background_col, x1, y1, x2, y2);
745 if (!is_single_image) {
746 if ((sseq->draw_flag & SEQ_DRAW_OFFSET_EXT) || (seq == special_seq_update)) {
747 draw_sequence_extensions(scene, ar, seq);
751 draw_seq_handle(v2d, seq, handsize_clamped, SEQ_LEFTHANDLE);
752 draw_seq_handle(v2d, seq, handsize_clamped, SEQ_RIGHTHANDLE);
754 /* draw the strip outline */
758 /* draw sound wave */
759 if (seq->type == SEQ_TYPE_SOUND_RAM) {
760 if (!(sseq->flag & SEQ_NO_WAVEFORMS)) {
761 drawseqwave(C, sseq, scene, seq, x1, y1, x2, y2, BLI_rctf_size_x(&ar->v2d.cur) / ar->winx);
766 if (seq->flag & SEQ_LOCK) {
767 glEnable(GL_POLYGON_STIPPLE);
771 glColor4ub(255, 255, 255, 32);
772 glPolygonStipple(stipple_diag_stripes_pos);
773 glRectf(x1, y1, x2, y2);
776 glColor4ub(0, 0, 0, 32);
777 glPolygonStipple(stipple_diag_stripes_neg);
778 glRectf(x1, y1, x2, y2);
780 glDisable(GL_POLYGON_STIPPLE);
784 if (!BKE_sequence_is_valid_check(seq)) {
785 glEnable(GL_POLYGON_STIPPLE);
788 glColor4ub(255, 0, 0, 255);
789 glPolygonStipple(stipple_diag_stripes_pos);
790 glRectf(x1, y1, x2, y2);
792 glDisable(GL_POLYGON_STIPPLE);
795 color3ubv_from_seq(scene, seq, col);
796 if ((G.moving & G_TRANSFORM_SEQ) && (seq->flag & SELECT)) {
797 if (seq->flag & SEQ_OVERLAP) {
798 col[0] = 255; col[1] = col[2] = 40;
801 UI_GetColorPtrShade3ubv(col, col, 120 + outline_tint);
804 UI_GetColorPtrShade3ubv(col, col, outline_tint);
806 glColor3ubv((GLubyte *)col);
808 if (seq->flag & SEQ_MUTE) {
809 glEnable(GL_LINE_STIPPLE);
810 glLineStipple(1, 0x8888);
813 UI_draw_roundbox_shade_x(GL_LINE_LOOP, x1, y1, x2, y2, 0.0, 0.1, 0.0);
815 if (seq->flag & SEQ_MUTE) {
816 glDisable(GL_LINE_STIPPLE);
819 if (seq->type == SEQ_TYPE_META) {
820 drawmeta_contents(scene, seq, x1, y1, x2, y2);
823 /* calculate if seq is long enough to print a name */
824 x1 = seq->startdisp + handsize_clamped;
825 x2 = seq->enddisp - handsize_clamped;
827 /* info text on the strip */
828 if (x1 < v2d->cur.xmin) x1 = v2d->cur.xmin;
829 else if (x1 > v2d->cur.xmax) x1 = v2d->cur.xmax;
830 if (x2 < v2d->cur.xmin) x2 = v2d->cur.xmin;
831 else if (x2 > v2d->cur.xmax) x2 = v2d->cur.xmax;
833 /* nice text here would require changing the view matrix for texture text */
834 if ((x2 - x1) / pixelx > 32) {
835 draw_seq_text(v2d, seq, x1, x2, y1, y2, background_col);
839 void sequencer_special_update_set(Sequence *seq)
841 special_seq_update = seq;
844 Sequence *ED_sequencer_special_preview_get(void)
846 return special_seq_update;
849 void ED_sequencer_special_preview_set(bContext *C, const int mval[2])
851 Scene *scene = CTX_data_scene(C);
852 ARegion *ar = CTX_wm_region(C);
855 seq = find_nearest_seq(scene, &ar->v2d, &hand, mval);
856 sequencer_special_update_set(seq);
859 void ED_sequencer_special_preview_clear(void)
861 sequencer_special_update_set(NULL);
864 ImBuf *sequencer_ibuf_get(struct Main *bmain, Scene *scene, SpaceSeq *sseq, int cfra, int frame_ofs, const char *viewname)
866 SeqRenderData context;
870 float proxy_size = 100.0;
871 short is_break = G.is_break;
873 render_size = sseq->render_size;
874 if (render_size == 0) {
875 render_size = scene->r.size;
878 proxy_size = render_size;
881 if (render_size < 0) {
885 rectx = (render_size * (float)scene->r.xsch) / 100.0f + 0.5f;
886 recty = (render_size * (float)scene->r.ysch) / 100.0f + 0.5f;
888 BKE_sequencer_new_render_data(
889 bmain->eval_ctx, bmain, scene,
890 rectx, recty, proxy_size,
892 context.view_id = BKE_scene_multiview_view_id_get(&scene->r, viewname);
894 /* sequencer could start rendering, in this case we need to be sure it wouldn't be canceled
895 * by Esc pressed somewhere in the past
899 if (special_seq_update)
900 ibuf = BKE_sequencer_give_ibuf_direct(&context, cfra + frame_ofs, special_seq_update);
901 else if (!U.prefetchframes) // XXX || (G.f & G_PLAYANIM) == 0) {
902 ibuf = BKE_sequencer_give_ibuf(&context, cfra + frame_ofs, sseq->chanshown);
904 ibuf = BKE_sequencer_give_ibuf_threaded(&context, cfra + frame_ofs, sseq->chanshown);
906 /* restore state so real rendering would be canceled (if needed) */
907 G.is_break = is_break;
912 static void sequencer_check_scopes(SequencerScopes *scopes, ImBuf *ibuf)
914 if (scopes->reference_ibuf != ibuf) {
915 if (scopes->zebra_ibuf) {
916 IMB_freeImBuf(scopes->zebra_ibuf);
917 scopes->zebra_ibuf = NULL;
920 if (scopes->waveform_ibuf) {
921 IMB_freeImBuf(scopes->waveform_ibuf);
922 scopes->waveform_ibuf = NULL;
925 if (scopes->sep_waveform_ibuf) {
926 IMB_freeImBuf(scopes->sep_waveform_ibuf);
927 scopes->sep_waveform_ibuf = NULL;
930 if (scopes->vector_ibuf) {
931 IMB_freeImBuf(scopes->vector_ibuf);
932 scopes->vector_ibuf = NULL;
935 if (scopes->histogram_ibuf) {
936 IMB_freeImBuf(scopes->histogram_ibuf);
937 scopes->histogram_ibuf = NULL;
942 static ImBuf *sequencer_make_scope(Scene *scene, ImBuf *ibuf, ImBuf *(*make_scope_cb) (ImBuf *ibuf))
944 ImBuf *display_ibuf = IMB_dupImBuf(ibuf);
947 IMB_colormanagement_imbuf_make_display_space(display_ibuf, &scene->view_settings,
948 &scene->display_settings);
950 scope = make_scope_cb(display_ibuf);
952 IMB_freeImBuf(display_ibuf);
957 static void sequencer_display_size(Scene *scene, SpaceSeq *sseq, float r_viewrect[2])
959 float render_size, proxy_size;
961 if (sseq->render_size == SEQ_PROXY_RENDER_SIZE_SCENE) {
962 render_size = (float)scene->r.size / 100.0f;
966 render_size = (float)sseq->render_size / 100.0f;
967 proxy_size = render_size;
970 r_viewrect[0] = (render_size * (float)scene->r.xsch);
971 r_viewrect[1] = (render_size * (float)scene->r.ysch);
973 /* rectx = viewrectx + 0.5f; */ /* UNUSED */
974 /* recty = viewrecty + 0.5f; */ /* UNUSED */
976 if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
977 r_viewrect[0] *= scene->r.xasp / scene->r.yasp;
978 r_viewrect[0] /= proxy_size;
979 r_viewrect[1] /= proxy_size;
983 static void sequencer_draw_gpencil(const bContext *C)
985 /* draw grease-pencil (image aligned) */
986 ED_gpencil_draw_2dimage(C);
988 /* ortho at pixel level */
989 UI_view2d_view_restore(C);
991 /* draw grease-pencil (screen aligned) */
992 ED_gpencil_draw_view2d(C, 0);
995 /* draws content borders plus safety borders if needed */
996 static void sequencer_draw_borders(const SpaceSeq *sseq, const View2D *v2d, const Scene *scene)
998 float x1 = v2d->tot.xmin;
999 float y1 = v2d->tot.ymin;
1000 float x2 = v2d->tot.xmax;
1001 float y2 = v2d->tot.ymax;
1006 UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 1.0, 0);
1008 glBegin(GL_LINE_LOOP);
1009 glVertex2f(x1 - 0.5f, y1 - 0.5f);
1010 glVertex2f(x1 - 0.5f, y2 + 0.5f);
1011 glVertex2f(x2 + 0.5f, y2 + 0.5f);
1012 glVertex2f(x2 + 0.5f, y1 - 0.5f);
1016 if (sseq->flag & SEQ_SHOW_SAFE_MARGINS) {
1019 scene->safe_areas.title,
1020 scene->safe_areas.action);
1022 if (sseq->flag & SEQ_SHOW_SAFE_CENTER) {
1025 scene->safe_areas.title_center,
1026 scene->safe_areas.action_center);
1033 /* draws checkerboard background for transparent content */
1034 static void sequencer_draw_background(const SpaceSeq *sseq, View2D *v2d, const float viewrect[2])
1036 /* setting up the view */
1037 UI_view2d_totRect_set(v2d, viewrect[0] + 0.5f, viewrect[1] + 0.5f);
1038 UI_view2d_curRect_validate(v2d);
1039 UI_view2d_view_ortho(v2d);
1041 /* only draw alpha for main buffer */
1042 if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1043 if (sseq->flag & SEQ_USE_ALPHA) {
1045 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1047 fdrawcheckerboard(v2d->tot.xmin, v2d->tot.ymin, v2d->tot.xmax, v2d->tot.ymax);
1048 glColor4f(1.0, 1.0, 1.0, 1.0);
1053 void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq, int cfra, int frame_ofs, bool draw_overlay, bool draw_backdrop)
1055 struct Main *bmain = CTX_data_main(C);
1056 struct ImBuf *ibuf = NULL;
1057 struct ImBuf *scope = NULL;
1058 struct View2D *v2d = &ar->v2d;
1059 /* int rectx, recty; */ /* UNUSED */
1064 void *display_buffer;
1065 void *cache_handle = NULL;
1066 const bool is_imbuf = ED_space_sequencer_check_show_imbuf(sseq);
1068 bool glsl_used = false;
1069 const bool draw_gpencil = ((sseq->flag & SEQ_SHOW_GPENCIL) && sseq->gpd);
1070 const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME};
1072 if (G.is_rendering == false && (scene->r.seq_flag & R_SEQ_GL_PREV) == 0) {
1073 /* stop all running jobs, except screen one. currently previews frustrate Render
1074 * needed to make so sequencer's rendering doesn't conflict with compositor
1076 WM_jobs_kill_type(CTX_wm_manager(C), NULL, WM_JOB_TYPE_COMPOSITE);
1078 if ((scene->r.seq_flag & R_SEQ_GL_PREV) == 0) {
1079 /* in case of final rendering used for preview, kill all previews,
1080 * otherwise threading conflict will happen in rendering module
1082 WM_jobs_kill_type(CTX_wm_manager(C), NULL, WM_JOB_TYPE_RENDER_PREVIEW);
1086 if ((!draw_overlay || sseq->overlay_type == SEQ_DRAW_OVERLAY_REFERENCE) && !draw_backdrop) {
1087 UI_GetThemeColor3fv(TH_SEQ_PREVIEW, col);
1088 glClearColor(col[0], col[1], col[2], 0.0);
1089 glClear(GL_COLOR_BUFFER_BIT);
1092 /* without this colors can flicker from previous opengl state */
1093 glColor4ub(255, 255, 255, 255);
1095 /* only initialize the preview if a render is in progress */
1099 if (sseq->render_size == SEQ_PROXY_RENDER_SIZE_NONE) {
1103 /* for now we only support Left/Right */
1104 ibuf = sequencer_ibuf_get(bmain, scene, sseq, cfra, frame_ofs, names[sseq->multiview_eye]);
1106 if ((ibuf == NULL) ||
1107 (ibuf->rect == NULL && ibuf->rect_float == NULL))
1109 /* gpencil can also be drawn if no imbuf is invalid */
1110 if (draw_gpencil && is_imbuf) {
1111 sequencer_display_size(scene, sseq, viewrect);
1113 sequencer_draw_background(sseq, v2d, viewrect);
1114 sequencer_draw_borders(sseq, v2d, scene);
1116 sequencer_draw_gpencil(C);
1121 sequencer_display_size(scene, sseq, viewrect);
1123 if (!draw_backdrop && (sseq->mainb != SEQ_DRAW_IMG_IMBUF || sseq->zebra != 0)) {
1124 SequencerScopes *scopes = &sseq->scopes;
1126 sequencer_check_scopes(scopes, ibuf);
1128 switch (sseq->mainb) {
1129 case SEQ_DRAW_IMG_IMBUF:
1130 if (!scopes->zebra_ibuf) {
1131 ImBuf *display_ibuf = IMB_dupImBuf(ibuf);
1133 if (display_ibuf->rect_float) {
1134 IMB_colormanagement_imbuf_make_display_space(display_ibuf, &scene->view_settings,
1135 &scene->display_settings);
1137 scopes->zebra_ibuf = make_zebra_view_from_ibuf(display_ibuf, sseq->zebra);
1138 IMB_freeImBuf(display_ibuf);
1140 scope = scopes->zebra_ibuf;
1142 case SEQ_DRAW_IMG_WAVEFORM:
1143 if ((sseq->flag & SEQ_DRAW_COLOR_SEPARATED) != 0) {
1144 if (!scopes->sep_waveform_ibuf)
1145 scopes->sep_waveform_ibuf = sequencer_make_scope(scene, ibuf, make_sep_waveform_view_from_ibuf);
1146 scope = scopes->sep_waveform_ibuf;
1149 if (!scopes->waveform_ibuf)
1150 scopes->waveform_ibuf = sequencer_make_scope(scene, ibuf, make_waveform_view_from_ibuf);
1151 scope = scopes->waveform_ibuf;
1154 case SEQ_DRAW_IMG_VECTORSCOPE:
1155 if (!scopes->vector_ibuf)
1156 scopes->vector_ibuf = sequencer_make_scope(scene, ibuf, make_vectorscope_view_from_ibuf);
1157 scope = scopes->vector_ibuf;
1159 case SEQ_DRAW_IMG_HISTOGRAM:
1160 if (!scopes->histogram_ibuf)
1161 scopes->histogram_ibuf = sequencer_make_scope(scene, ibuf, make_histogram_view_from_ibuf);
1162 scope = scopes->histogram_ibuf;
1166 /* future files may have new scopes we don't catch above */
1168 scopes->reference_ibuf = ibuf;
1169 if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1170 /* scopes drawn in image preview use viewrect from orig ibuf - currently that's only zebra */
1173 viewrect[0] = scope->x;
1174 viewrect[1] = scope->y;
1178 scopes->reference_ibuf = NULL;
1182 if (!draw_backdrop) {
1183 sequencer_draw_background(sseq, v2d, viewrect);
1187 IMB_freeImBuf(ibuf);
1190 if (ibuf->rect_float && ibuf->rect == NULL) {
1191 IMB_rect_from_float(ibuf);
1194 display_buffer = (unsigned char *)ibuf->rect;
1196 type = GL_UNSIGNED_BYTE;
1199 bool force_fallback = false;
1201 force_fallback |= (U.image_draw_method != IMAGE_DRAW_METHOD_GLSL);
1202 force_fallback |= (ibuf->dither != 0.0f);
1204 if (force_fallback) {
1205 /* Fallback to CPU based color space conversion */
1208 type = GL_UNSIGNED_BYTE;
1209 display_buffer = NULL;
1211 else if (ibuf->rect_float) {
1212 display_buffer = ibuf->rect_float;
1214 if (ibuf->channels == 4) {
1217 else if (ibuf->channels == 3) {
1221 BLI_assert(!"Incompatible number of channels for float buffer in sequencer");
1223 display_buffer = NULL;
1228 if (ibuf->float_colorspace) {
1229 glsl_used = IMB_colormanagement_setup_glsl_draw_from_space_ctx(C, ibuf->float_colorspace, ibuf->dither, true);
1232 glsl_used = IMB_colormanagement_setup_glsl_draw_ctx(C, ibuf->dither, true);
1235 else if (ibuf->rect) {
1236 display_buffer = ibuf->rect;
1238 type = GL_UNSIGNED_BYTE;
1240 glsl_used = IMB_colormanagement_setup_glsl_draw_from_space_ctx(C, ibuf->rect_colorspace, ibuf->dither, false);
1244 type = GL_UNSIGNED_BYTE;
1245 display_buffer = NULL;
1248 /* there's a data to be displayed, but GLSL is not initialized
1249 * properly, in this case we fallback to CPU-based display transform
1251 if ((ibuf->rect || ibuf->rect_float) && !glsl_used) {
1252 display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle);
1254 type = GL_UNSIGNED_BYTE;
1258 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1259 glColor4f(1.0, 1.0, 1.0, 1.0);
1261 last_texid = glaGetOneInteger(GL_TEXTURE_2D);
1262 glEnable(GL_TEXTURE_2D);
1263 glGenTextures(1, (GLuint *)&texid);
1265 glBindTexture(GL_TEXTURE_2D, texid);
1267 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1268 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1270 if (type == GL_FLOAT)
1271 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, ibuf->x, ibuf->y, 0, format, type, display_buffer);
1273 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ibuf->x, ibuf->y, 0, format, type, display_buffer);
1275 if (draw_backdrop) {
1276 glMatrixMode(GL_PROJECTION);
1279 glMatrixMode(GL_MODELVIEW);
1286 if (sseq->overlay_type == SEQ_DRAW_OVERLAY_RECT) {
1288 tot_clip.xmin = v2d->tot.xmin + (fabsf(BLI_rctf_size_x(&v2d->tot)) * scene->ed->over_border.xmin);
1289 tot_clip.ymin = v2d->tot.ymin + (fabsf(BLI_rctf_size_y(&v2d->tot)) * scene->ed->over_border.ymin);
1290 tot_clip.xmax = v2d->tot.xmin + (fabsf(BLI_rctf_size_x(&v2d->tot)) * scene->ed->over_border.xmax);
1291 tot_clip.ymax = v2d->tot.ymin + (fabsf(BLI_rctf_size_y(&v2d->tot)) * scene->ed->over_border.ymax);
1293 glTexCoord2f(scene->ed->over_border.xmin, scene->ed->over_border.ymin); glVertex2f(tot_clip.xmin, tot_clip.ymin);
1294 glTexCoord2f(scene->ed->over_border.xmin, scene->ed->over_border.ymax); glVertex2f(tot_clip.xmin, tot_clip.ymax);
1295 glTexCoord2f(scene->ed->over_border.xmax, scene->ed->over_border.ymax); glVertex2f(tot_clip.xmax, tot_clip.ymax);
1296 glTexCoord2f(scene->ed->over_border.xmax, scene->ed->over_border.ymin); glVertex2f(tot_clip.xmax, tot_clip.ymin);
1298 else if (sseq->overlay_type == SEQ_DRAW_OVERLAY_REFERENCE) {
1299 glTexCoord2f(0.0f, 0.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymin);
1300 glTexCoord2f(0.0f, 1.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymax);
1301 glTexCoord2f(1.0f, 1.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymax);
1302 glTexCoord2f(1.0f, 0.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymin);
1305 else if (draw_backdrop) {
1306 float aspect = BLI_rcti_size_x(&ar->winrct) / (float)BLI_rcti_size_y(&ar->winrct);
1307 float image_aspect = viewrect[0] / viewrect[1];
1308 float imagex, imagey;
1310 if (aspect >= image_aspect) {
1311 imagex = image_aspect / aspect;
1316 imagey = aspect / image_aspect;
1319 glTexCoord2f(0.0f, 0.0f); glVertex2f(-imagex, -imagey);
1320 glTexCoord2f(0.0f, 1.0f); glVertex2f(-imagex, imagey);
1321 glTexCoord2f(1.0f, 1.0f); glVertex2f(imagex, imagey);
1322 glTexCoord2f(1.0f, 0.0f); glVertex2f(imagex, -imagey);
1325 glTexCoord2f(0.0f, 0.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymin);
1326 glTexCoord2f(0.0f, 1.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymax);
1327 glTexCoord2f(1.0f, 1.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymax);
1328 glTexCoord2f(1.0f, 0.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymin);
1332 if (draw_backdrop) {
1334 glMatrixMode(GL_PROJECTION);
1336 glMatrixMode(GL_MODELVIEW);
1340 glBindTexture(GL_TEXTURE_2D, last_texid);
1341 glDisable(GL_TEXTURE_2D);
1342 if (sseq->mainb == SEQ_DRAW_IMG_IMBUF && sseq->flag & SEQ_USE_ALPHA)
1343 glDisable(GL_BLEND);
1344 glDeleteTextures(1, &texid);
1347 IMB_colormanagement_finish_glsl_draw();
1350 IMB_display_buffer_release(cache_handle);
1353 IMB_freeImBuf(ibuf);
1355 if (draw_backdrop) {
1359 if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1360 sequencer_draw_borders(sseq, v2d, scene);
1363 if (draw_gpencil && is_imbuf) {
1364 sequencer_draw_gpencil(C);
1367 /* ortho at pixel level */
1368 UI_view2d_view_restore(C);
1372 /* NOTE: sequencer mask editing isnt finished, the draw code is working but editing not,
1373 * for now just disable drawing since the strip frame will likely be offset */
1375 //if (sc->mode == SC_MODE_MASKEDIT) {
1376 if (0 && sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1377 Mask *mask = BKE_sequencer_mask_get(scene);
1381 float aspx = 1.0f, aspy = 1.0f;
1382 // ED_mask_get_size(C, &width, &height);
1384 //Scene *scene = CTX_data_scene(C);
1385 width = (scene->r.size * scene->r.xsch) / 100;
1386 height = (scene->r.size * scene->r.ysch) / 100;
1388 ED_mask_draw_region(mask, ar,
1399 void drawprefetchseqspace(Scene *scene, ARegion *UNUSED(ar), SpaceSeq *sseq)
1402 int render_size = sseq->render_size;
1403 int proxy_size = 100.0;
1404 if (render_size == 0) {
1405 render_size = scene->r.size;
1408 proxy_size = render_size;
1410 if (render_size < 0) {
1414 rectx = (render_size * scene->r.xsch) / 100;
1415 recty = (render_size * scene->r.ysch) / 100;
1417 if (sseq->mainb != SEQ_DRAW_SEQUENCE) {
1418 give_ibuf_prefetch_request(
1419 rectx, recty, (scene->r.cfra), sseq->chanshown,
1425 /* draw backdrop of the sequencer strips view */
1426 static void draw_seq_backdrop(View2D *v2d)
1430 /* darker gray overlay over the view backdrop */
1431 UI_ThemeColorShade(TH_BACK, -20);
1432 glRectf(v2d->cur.xmin, -1.0, v2d->cur.xmax, 1.0);
1434 /* Alternating horizontal stripes */
1435 i = max_ii(1, ((int)v2d->cur.ymin) - 1);
1438 while (i < v2d->cur.ymax) {
1440 UI_ThemeColorShade(TH_BACK, -15);
1442 UI_ThemeColorShade(TH_BACK, -25);
1444 glVertex2f(v2d->cur.xmax, i);
1445 glVertex2f(v2d->cur.xmin, i);
1446 glVertex2f(v2d->cur.xmin, i + 1);
1447 glVertex2f(v2d->cur.xmax, i + 1);
1453 /* Darker lines separating the horizontal bands */
1454 i = max_ii(1, ((int)v2d->cur.ymin) - 1);
1455 UI_ThemeColor(TH_GRID);
1458 while (i < v2d->cur.ymax) {
1459 glVertex2f(v2d->cur.xmax, i);
1460 glVertex2f(v2d->cur.xmin, i);
1467 /* draw the contents of the sequencer strips view */
1468 static void draw_seq_strips(const bContext *C, Editing *ed, ARegion *ar)
1470 Scene *scene = CTX_data_scene(C);
1471 View2D *v2d = &ar->v2d;
1472 SpaceSeq *sseq = CTX_wm_space_seq(C);
1473 Sequence *last_seq = BKE_sequencer_active_get(scene);
1475 float pixelx = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask);
1477 /* loop through twice, first unselected, then selected */
1478 for (j = 0; j < 2; j++) {
1480 int outline_tint = (j) ? -60 : -150; /* highlighting around strip edges indicating selection */
1482 /* loop through strips, checking for those that are visible */
1483 for (seq = ed->seqbasep->first; seq; seq = seq->next) {
1484 /* boundbox and selection tests for NOT drawing the strip... */
1485 if ((seq->flag & SELECT) != sel) continue;
1486 else if (seq == last_seq) continue;
1487 else if (min_ii(seq->startdisp, seq->start) > v2d->cur.xmax) continue;
1488 else if (max_ii(seq->enddisp, seq->start + seq->len) < v2d->cur.xmin) continue;
1489 else if (seq->machine + 1.0f < v2d->cur.ymin) continue;
1490 else if (seq->machine > v2d->cur.ymax) continue;
1492 /* strip passed all tests unscathed... so draw it now */
1493 draw_seq_strip(C, sseq, scene, ar, seq, outline_tint, pixelx);
1496 /* draw selected next time round */
1500 /* draw the last selected last (i.e. 'active' in other parts of Blender), removes some overlapping error */
1502 draw_seq_strip(C, sseq, scene, ar, last_seq, 120, pixelx);
1504 /* draw highlight when previewing a single strip */
1505 if (special_seq_update) {
1506 const Sequence *seq = special_seq_update;
1508 glColor4ub(255, 255, 255, 48);
1509 glRectf(seq->startdisp, seq->machine + SEQ_STRIP_OFSBOTTOM, seq->enddisp, seq->machine + SEQ_STRIP_OFSTOP);
1510 glDisable(GL_BLEND);
1514 static void seq_draw_sfra_efra(Scene *scene, View2D *v2d)
1516 const Editing *ed = BKE_sequencer_editing_get(scene, false);
1517 const int frame_sta = PSFRA;
1518 const int frame_end = PEFRA + 1;
1522 /* draw darkened area outside of active timeline
1523 * frame range used is preview range or scene range */
1524 UI_ThemeColorShadeAlpha(TH_BACK, -25, -100);
1526 if (frame_sta < frame_end) {
1527 glRectf(v2d->cur.xmin, v2d->cur.ymin, (float)frame_sta, v2d->cur.ymax);
1528 glRectf((float)frame_end, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
1531 glRectf(v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
1534 UI_ThemeColorShade(TH_BACK, -60);
1535 /* thin lines where the actual frames are */
1536 fdrawline(frame_sta, v2d->cur.ymin, frame_sta, v2d->cur.ymax);
1537 fdrawline(frame_end, v2d->cur.ymin, frame_end, v2d->cur.ymax);
1539 if (ed && !BLI_listbase_is_empty(&ed->metastack)) {
1540 MetaStack *ms = ed->metastack.last;
1542 glColor4ub(255, 255, 255, 8);
1543 glRectf(ms->disp_range[0], v2d->cur.ymin, ms->disp_range[1], v2d->cur.ymax);
1545 UI_ThemeColorShade(TH_BACK, -40);
1547 fdrawline(ms->disp_range[0], v2d->cur.ymin, ms->disp_range[0], v2d->cur.ymax);
1548 fdrawline(ms->disp_range[1], v2d->cur.ymin, ms->disp_range[1], v2d->cur.ymax);
1551 glDisable(GL_BLEND);
1554 /* Draw Timeline/Strip Editor Mode for Sequencer */
1555 void draw_timeline_seq(const bContext *C, ARegion *ar)
1557 Scene *scene = CTX_data_scene(C);
1558 Editing *ed = BKE_sequencer_editing_get(scene, false);
1559 SpaceSeq *sseq = CTX_wm_space_seq(C);
1560 View2D *v2d = &ar->v2d;
1561 View2DScrollers *scrollers;
1562 short unit = 0, flag = 0;
1565 /* clear and setup matrix */
1566 UI_GetThemeColor3fv(TH_BACK, col);
1567 if (ed && ed->metastack.first)
1568 glClearColor(col[0], col[1], col[2] - 0.1f, 0.0f);
1570 glClearColor(col[0], col[1], col[2], 0.0f);
1571 glClear(GL_COLOR_BUFFER_BIT);
1573 UI_view2d_view_ortho(v2d);
1576 /* calculate extents of sequencer strips/data
1577 * NOTE: needed for the scrollers later
1579 boundbox_seq(scene, &v2d->tot);
1583 draw_seq_backdrop(v2d);
1585 /* regular grid-pattern over the rest of the view (i.e. 25-frame grid lines) */
1586 // NOTE: the gridlines are currently spaced every 25 frames, which is only fine for 25 fps, but maybe not for 30...
1587 UI_view2d_constant_grid_draw(v2d);
1589 if (sseq->draw_flag & SEQ_DRAW_BACKDROP) {
1590 draw_image_seq(C, scene, ar, sseq, scene->r.cfra, 0, false, true);
1591 UI_view2d_view_ortho(v2d);
1594 ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
1596 seq_draw_sfra_efra(scene, v2d);
1598 /* sequence strips (if there is data available to be drawn) */
1601 draw_seq_strips(C, ed, ar);
1603 /* text draw cached (for sequence names), in pixelspace now */
1604 UI_view2d_text_cache_draw(ar);
1608 UI_view2d_view_ortho(v2d);
1609 if ((sseq->flag & SEQ_DRAWFRAMES) == 0) flag |= DRAWCFRA_UNIT_SECONDS;
1610 if ((sseq->flag & SEQ_NO_DRAW_CFRANUM) == 0) flag |= DRAWCFRA_SHOW_NUMBOX;
1611 ANIM_draw_cfra(C, v2d, flag);
1614 UI_view2d_view_orthoSpecial(ar, v2d, 1);
1615 ED_markers_draw(C, DRAW_MARKERS_LINES | DRAW_MARKERS_MARGIN);
1618 UI_view2d_view_ortho(v2d);
1619 ANIM_draw_previewrange(C, v2d, 1);
1621 /* overlap playhead */
1622 if (scene->ed && scene->ed->over_flag & SEQ_EDIT_OVERLAY_SHOW) {
1623 int cfra_over = (scene->ed->over_flag & SEQ_EDIT_OVERLAY_ABS) ? scene->ed->over_cfra : scene->r.cfra + scene->ed->over_ofs;
1624 glColor3f(0.2, 0.2, 0.2);
1625 // glRectf(cfra_over, v2d->cur.ymin, scene->ed->over_ofs + scene->r.cfra + 1, v2d->cur.ymax);
1628 glVertex2f(cfra_over, v2d->cur.ymin);
1629 glVertex2f(cfra_over, v2d->cur.ymax);
1635 ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
1637 /* reset view matrix */
1638 UI_view2d_view_restore(C);
1641 unit = (sseq->flag & SEQ_DRAWFRAMES) ? V2D_UNIT_FRAMES : V2D_UNIT_SECONDS;
1642 scrollers = UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_UNIT_VALUES, V2D_GRID_CLAMP);
1643 UI_view2d_scrollers_draw(C, v2d, scrollers);
1644 UI_view2d_scrollers_free(scrollers);