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 "MEM_guardedalloc.h"
36 #include "BLI_blenlib.h"
38 #include "BLI_utildefines.h"
40 #include "IMB_imbuf_types.h"
42 #include "DNA_scene_types.h"
43 #include "DNA_mask_types.h"
44 #include "DNA_screen_types.h"
45 #include "DNA_space_types.h"
46 #include "DNA_userdef_types.h"
47 #include "DNA_sound_types.h"
49 #include "BKE_context.h"
50 #include "BKE_global.h"
51 #include "BKE_sequencer.h"
53 #include "BKE_sound.h"
55 #include "IMB_imbuf.h"
58 #include "BIF_glutil.h"
60 #include "ED_anim_api.h"
61 #include "ED_gpencil.h"
62 #include "ED_markers.h"
65 #include "ED_space_api.h"
67 #include "UI_interface.h"
68 #include "UI_resources.h"
69 #include "UI_view2d.h"
72 #include "sequencer_intern.h"
75 #define SEQ_LEFTHANDLE 1
76 #define SEQ_RIGHTHANDLE 2
78 #define SEQ_HANDLE_SIZE_MIN 7.0f
79 #define SEQ_HANDLE_SIZE_MAX 40.0f
82 /* Note, Don't use SEQ_BEGIN/SEQ_END while drawing!
83 * it messes up transform, - Campbell */
84 static void draw_shadedstrip(Sequence *seq, unsigned char col[3], float x1, float y1, float x2, float y2);
86 static void get_seq_color3ubv(Scene *curscene, Sequence *seq, unsigned char col[3])
88 unsigned char blendcol[3];
89 SolidColorVars *colvars = (SolidColorVars *)seq->effectdata;
93 UI_GetThemeColor3ubv(TH_SEQ_IMAGE, col);
97 UI_GetThemeColor3ubv(TH_SEQ_META, col);
101 UI_GetThemeColor3ubv(TH_SEQ_MOVIE, col);
104 case SEQ_TYPE_MOVIECLIP:
105 UI_GetThemeColor3ubv(TH_SEQ_MOVIECLIP, col);
109 UI_GetThemeColor3ubv(TH_SEQ_MASK, col); /* TODO */
113 UI_GetThemeColor3ubv(TH_SEQ_SCENE, col);
115 if (seq->scene == curscene) {
116 UI_GetColorPtrShade3ubv(col, col, 20);
122 case SEQ_TYPE_GAMCROSS:
124 UI_GetThemeColor3ubv(TH_SEQ_TRANSITION, col);
126 /* slightly offset hue to distinguish different effects */
127 if (seq->type == SEQ_TYPE_CROSS) rgb_byte_set_hue_float_offset(col, 0.04);
128 if (seq->type == SEQ_TYPE_GAMCROSS) rgb_byte_set_hue_float_offset(col, 0.08);
129 if (seq->type == SEQ_TYPE_WIPE) rgb_byte_set_hue_float_offset(col, 0.12);
133 case SEQ_TYPE_TRANSFORM:
138 case SEQ_TYPE_ALPHAOVER:
139 case SEQ_TYPE_ALPHAUNDER:
140 case SEQ_TYPE_OVERDROP:
142 case SEQ_TYPE_MULTICAM:
143 case SEQ_TYPE_ADJUSTMENT:
144 UI_GetThemeColor3ubv(TH_SEQ_EFFECT, col);
146 /* slightly offset hue to distinguish different effects */
147 if (seq->type == SEQ_TYPE_ADD) rgb_byte_set_hue_float_offset(col, 0.04);
148 else if (seq->type == SEQ_TYPE_SUB) rgb_byte_set_hue_float_offset(col, 0.08);
149 else if (seq->type == SEQ_TYPE_MUL) rgb_byte_set_hue_float_offset(col, 0.12);
150 else if (seq->type == SEQ_TYPE_ALPHAOVER) rgb_byte_set_hue_float_offset(col, 0.16);
151 else if (seq->type == SEQ_TYPE_ALPHAUNDER) rgb_byte_set_hue_float_offset(col, 0.20);
152 else if (seq->type == SEQ_TYPE_OVERDROP) rgb_byte_set_hue_float_offset(col, 0.24);
153 else if (seq->type == SEQ_TYPE_GLOW) rgb_byte_set_hue_float_offset(col, 0.28);
154 else if (seq->type == SEQ_TYPE_TRANSFORM) rgb_byte_set_hue_float_offset(col, 0.36);
155 else if (seq->type == SEQ_TYPE_MULTICAM) rgb_byte_set_hue_float_offset(col, 0.32);
156 else if (seq->type == SEQ_TYPE_ADJUSTMENT) rgb_byte_set_hue_float_offset(col, 0.40);
161 rgb_float_to_uchar(col, colvars->col);
164 col[0] = col[1] = col[2] = 128;
168 case SEQ_TYPE_SOUND_RAM:
169 UI_GetThemeColor3ubv(TH_SEQ_AUDIO, col);
170 blendcol[0] = blendcol[1] = blendcol[2] = 128;
171 if (seq->flag & SEQ_MUTE) UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.5, 20);
175 col[0] = 10; col[1] = 255; col[2] = 40;
179 static void drawseqwave(Scene *scene, Sequence *seq, float x1, float y1, float x2, float y2, float stepsize)
182 * x1 is the starting x value to draw the wave,
183 * x2 the end x value, same for y1 and y2
184 * stepsize is width of a pixel.
186 if (seq->flag & SEQ_AUDIO_DRAW_WAVEFORM) {
188 int length = floor((x2 - x1) / stepsize) + 1;
189 float ymid = (y1 + y2) / 2;
190 float yscale = (y2 - y1) / 2;
192 float startsample, endsample;
195 SoundWaveform *waveform;
197 if (!seq->sound->waveform)
198 sound_read_waveform(seq->sound);
200 if (!seq->sound->waveform)
201 return; /* zero length sound */
203 waveform = seq->sound->waveform;
208 startsample = floor((seq->startofs + seq->anim_startofs) / FPS * SOUND_WAVE_SAMPLES_PER_SECOND);
209 endsample = ceil((seq->startofs + seq->anim_startofs + seq->enddisp - seq->startdisp) / FPS * SOUND_WAVE_SAMPLES_PER_SECOND);
210 samplestep = (endsample - startsample) * stepsize / (x2 - x1);
212 if (length > floor((waveform->length - startsample) / samplestep))
213 length = floor((waveform->length - startsample) / samplestep);
215 glBegin(GL_LINE_STRIP);
216 for (i = 0; i < length; i++) {
217 pos = startsample + i * samplestep;
219 value = waveform->data[pos * 3];
221 for (j = pos + 1; (j < waveform->length) && (j < pos + samplestep); j++) {
222 if (value > waveform->data[j * 3])
223 value = waveform->data[j * 3];
226 glVertex2f(x1 + i * stepsize, ymid + value * yscale);
230 glBegin(GL_LINE_STRIP);
231 for (i = 0; i < length; i++) {
232 pos = startsample + i * samplestep;
234 value = waveform->data[pos * 3 + 1];
236 for (j = pos + 1; (j < waveform->length) && (j < pos + samplestep); j++) {
237 if (value < waveform->data[j * 3 + 1])
238 value = waveform->data[j * 3 + 1];
241 glVertex2f(x1 + i * stepsize, ymid + value * yscale);
247 static void drawmeta_stipple(int value)
250 glEnable(GL_POLYGON_STIPPLE);
251 glPolygonStipple(stipple_halftone);
253 glEnable(GL_LINE_STIPPLE);
254 glLineStipple(1, 0x8888);
257 glDisable(GL_POLYGON_STIPPLE);
258 glDisable(GL_LINE_STIPPLE);
262 static void drawmeta_contents(Scene *scene, Sequence *seqm, float x1, float y1, float x2, float y2)
264 /* note: this used to use SEQ_BEGIN/SEQ_END, but it messes up the
265 * seq->depth value, (needed by transform when doing overlap checks)
266 * so for now, just use the meta's immediate children, could be fixed but
267 * its only drawing - campbell */
269 unsigned char col[4];
271 int chan_min = MAXSEQ;
274 float draw_range = y2 - y1;
278 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
280 if (seqm->flag & SEQ_MUTE)
283 for (seq = seqm->seqbase.first; seq; seq = seq->next) {
284 chan_min = MIN2(chan_min, seq->machine);
285 chan_max = MAX2(chan_max, seq->machine);
288 chan_range = (chan_max - chan_min) + 1;
289 draw_height = draw_range / chan_range;
291 col[3] = 196; /* alpha, used for all meta children */
293 for (seq = seqm->seqbase.first; seq; seq = seq->next) {
294 if ((seq->startdisp > x2 || seq->enddisp < x1) == 0) {
295 float y_chan = (seq->machine - chan_min) / (float)(chan_range) * draw_range;
296 float x1_chan = seq->startdisp;
297 float x2_chan = seq->enddisp;
298 float y1_chan, y2_chan;
300 if ((seqm->flag & SEQ_MUTE) == 0 && (seq->flag & SEQ_MUTE))
303 get_seq_color3ubv(scene, seq, col);
307 /* clamp within parent sequence strip bounds */
308 if (x1_chan < x1) x1_chan = x1;
309 if (x2_chan > x2) x2_chan = x2;
311 y1_chan = y1 + y_chan + (draw_height * SEQ_STRIP_OFSBOTTOM);
312 y2_chan = y1 + y_chan + (draw_height * SEQ_STRIP_OFSTOP);
314 glRectf(x1_chan, y1_chan, x2_chan, y2_chan);
316 UI_GetColorPtrShade3ubv(col, col, -30);
318 fdrawbox(x1_chan, y1_chan, x2_chan, y2_chan);
320 if ((seqm->flag & SEQ_MUTE) == 0 && (seq->flag & SEQ_MUTE))
325 if (seqm->flag & SEQ_MUTE)
331 /* clamp handles to defined size in pixel space */
332 static float draw_seq_handle_size_get_clamped(Sequence *seq, const float pixelx)
334 const float minhandle = pixelx * SEQ_HANDLE_SIZE_MIN;
335 const float maxhandle = pixelx * SEQ_HANDLE_SIZE_MAX;
336 return CLAMPIS(seq->handsize, minhandle, maxhandle);
339 /* draw a handle, for each end of a sequence strip */
340 static void draw_seq_handle(View2D *v2d, Sequence *seq, const float handsize_clamped, const short direction)
342 float v1[2], v2[2], v3[2], rx1 = 0, rx2 = 0; //for triangles and rect
343 float x1, x2, y1, y2;
345 unsigned int whichsel = 0;
350 y1 = seq->machine + SEQ_STRIP_OFSBOTTOM;
351 y2 = seq->machine + SEQ_STRIP_OFSTOP;
353 /* set up co-ordinates/dimensions for either left or right handle */
354 if (direction == SEQ_LEFTHANDLE) {
356 rx2 = x1 + handsize_clamped * 0.75f;
358 v1[0] = x1 + handsize_clamped / 4; v1[1] = y1 + ( ((y1 + y2) / 2.0f - y1) / 2);
359 v2[0] = x1 + handsize_clamped / 4; v2[1] = y2 - ( ((y1 + y2) / 2.0f - y1) / 2);
360 v3[0] = v2[0] + handsize_clamped / 4; v3[1] = (y1 + y2) / 2.0f;
362 whichsel = SEQ_LEFTSEL;
364 else if (direction == SEQ_RIGHTHANDLE) {
365 rx1 = x2 - handsize_clamped * 0.75f;
368 v1[0] = x2 - handsize_clamped / 4; v1[1] = y1 + ( ((y1 + y2) / 2.0f - y1) / 2);
369 v2[0] = x2 - handsize_clamped / 4; v2[1] = y2 - ( ((y1 + y2) / 2.0f - y1) / 2);
370 v3[0] = v2[0] - handsize_clamped / 4; v3[1] = (y1 + y2) / 2.0f;
372 whichsel = SEQ_RIGHTSEL;
376 if (seq->type < SEQ_TYPE_EFFECT ||
377 BKE_sequence_effect_get_num_inputs(seq->type) == 0)
381 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
383 if (seq->flag & whichsel) glColor4ub(0, 0, 0, 80);
384 else if (seq->flag & SELECT) glColor4ub(255, 255, 255, 30);
385 else glColor4ub(0, 0, 0, 22);
387 glRectf(rx1, y1, rx2, y2);
389 if (seq->flag & whichsel) glColor4ub(255, 255, 255, 200);
390 else glColor4ub(0, 0, 0, 50);
392 glEnable(GL_POLYGON_SMOOTH);
393 glBegin(GL_TRIANGLES);
394 glVertex2fv(v1); glVertex2fv(v2); glVertex2fv(v3);
397 glDisable(GL_POLYGON_SMOOTH);
401 if (G.moving || (seq->flag & whichsel)) {
402 const char col[4] = {255, 255, 255, 255};
403 if (direction == SEQ_LEFTHANDLE) {
404 BLI_snprintf(numstr, sizeof(numstr), "%d", seq->startdisp);
409 BLI_snprintf(numstr, sizeof(numstr), "%d", seq->enddisp - 1);
410 x1 = x2 - handsize_clamped * 0.75f;
413 UI_view2d_text_cache_add(v2d, x1, y1, numstr, col);
417 static void draw_seq_extensions(Scene *scene, ARegion *ar, Sequence *seq)
419 float x1, x2, y1, y2, pixely, a;
420 unsigned char col[3], blendcol[3];
421 View2D *v2d = &ar->v2d;
423 if (seq->type >= SEQ_TYPE_EFFECT) return;
428 y1 = seq->machine + SEQ_STRIP_OFSBOTTOM;
429 y2 = seq->machine + SEQ_STRIP_OFSTOP;
431 pixely = BLI_RCT_SIZE_Y(&v2d->cur) / BLI_RCT_SIZE_Y(&v2d->mask);
433 if (pixely <= 0) return; /* can happen when the view is split/resized */
435 blendcol[0] = blendcol[1] = blendcol[2] = 120;
439 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
441 get_seq_color3ubv(scene, seq, col);
443 if (seq->flag & SELECT) {
444 UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.3, -40);
445 glColor4ub(col[0], col[1], col[2], 170);
448 UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.6, 0);
449 glColor4ub(col[0], col[1], col[2], 110);
452 glRectf((float)(seq->start), y1 - SEQ_STRIP_OFSBOTTOM, x1, y1);
454 if (seq->flag & SELECT) glColor4ub(col[0], col[1], col[2], 255);
455 else glColor4ub(col[0], col[1], col[2], 160);
457 fdrawbox((float)(seq->start), y1 - SEQ_STRIP_OFSBOTTOM, x1, y1); //outline
463 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
465 get_seq_color3ubv(scene, seq, col);
467 if (seq->flag & SELECT) {
468 UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.3, -40);
469 glColor4ub(col[0], col[1], col[2], 170);
472 UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.6, 0);
473 glColor4ub(col[0], col[1], col[2], 110);
476 glRectf(x2, y2, (float)(seq->start + seq->len), y2 + SEQ_STRIP_OFSBOTTOM);
478 if (seq->flag & SELECT) glColor4ub(col[0], col[1], col[2], 255);
479 else glColor4ub(col[0], col[1], col[2], 160);
481 fdrawbox(x2, y2, (float)(seq->start + seq->len), y2 + SEQ_STRIP_OFSBOTTOM); //outline
485 if (seq->startstill) {
486 get_seq_color3ubv(scene, seq, col);
487 UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.75, 40);
488 glColor3ubv((GLubyte *)col);
490 draw_shadedstrip(seq, col, x1, y1, (float)(seq->start), y2);
492 /* feint pinstripes, helps see exactly which is extended and which isn't,
493 * especially when the extension is very small */
494 if (seq->flag & SELECT) UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, 24);
495 else UI_GetColorPtrShade3ubv(col, col, -16);
497 glColor3ubv((GLubyte *)col);
499 for (a = y1; a < y2; a += pixely * 2.0f) {
500 fdrawline(x1, a, (float)(seq->start), a);
504 get_seq_color3ubv(scene, seq, col);
505 UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.75, 40);
506 glColor3ubv((GLubyte *)col);
508 draw_shadedstrip(seq, col, (float)(seq->start + seq->len), y1, x2, y2);
510 /* feint pinstripes, helps see exactly which is extended and which isn't,
511 * especially when the extension is very small */
512 if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, 24);
513 else UI_GetColorPtrShade3ubv(col, col, -16);
515 glColor3ubv((GLubyte *)col);
517 for (a = y1; a < y2; a += pixely * 2.0f) {
518 fdrawline((float)(seq->start + seq->len), a, x2, a);
523 /* draw info text on a sequence strip */
524 static void draw_seq_text(View2D *v2d, Sequence *seq, float x1, float x2, float y1, float y2, const unsigned char background_col[3])
527 char str[32 + FILE_MAX];
528 const char *name = seq->name + 2;
531 /* note, all strings should include 'name' */
533 name = BKE_sequence_give_name(seq);
535 if (seq->type == SEQ_TYPE_META || seq->type == SEQ_TYPE_ADJUSTMENT) {
536 BLI_snprintf(str, sizeof(str), "%s | %d", name, seq->len);
538 else if (seq->type == SEQ_TYPE_SCENE) {
540 if (seq->scene_camera) {
541 BLI_snprintf(str, sizeof(str), "%s: %s (%s) | %d",
542 name, seq->scene->id.name + 2, ((ID *)seq->scene_camera)->name + 2, seq->len);
545 BLI_snprintf(str, sizeof(str), "%s: %s | %d",
546 name, seq->scene->id.name + 2, seq->len);
550 BLI_snprintf(str, sizeof(str), "%s | %d",
554 else if (seq->type == SEQ_TYPE_MOVIECLIP) {
555 if (seq->clip && strcmp(name, seq->clip->id.name + 2) != 0) {
556 BLI_snprintf(str, sizeof(str), "%s: %s | %d",
557 name, seq->clip->id.name + 2, seq->len);
560 BLI_snprintf(str, sizeof(str), "%s | %d",
564 else if (seq->type == SEQ_TYPE_MASK) {
565 if (seq->mask && strcmp(name, seq->mask->id.name + 2) != 0) {
566 BLI_snprintf(str, sizeof(str), "%s: %s | %d",
567 name, seq->mask->id.name + 2, seq->len);
570 BLI_snprintf(str, sizeof(str), "%s | %d",
574 else if (seq->type == SEQ_TYPE_MULTICAM) {
575 BLI_snprintf(str, sizeof(str), "Cam %s: %d",
576 name, seq->multicam_source);
578 else if (seq->type == SEQ_TYPE_IMAGE) {
579 BLI_snprintf(str, sizeof(str), "%s: %s%s | %d",
580 name, seq->strip->dir, seq->strip->stripdata->name, seq->len);
582 else if (seq->type & SEQ_TYPE_EFFECT) {
583 BLI_snprintf(str, sizeof(str), "%s | %d",
586 else if (seq->type == SEQ_TYPE_SOUND_RAM) {
588 BLI_snprintf(str, sizeof(str), "%s: %s | %d",
589 name, seq->sound->name, seq->len);
591 BLI_snprintf(str, sizeof(str), "%s | %d",
594 else if (seq->type == SEQ_TYPE_MOVIE) {
595 BLI_snprintf(str, sizeof(str), "%s: %s%s | %d",
596 name, seq->strip->dir, seq->strip->stripdata->name, seq->len);
599 if (seq->flag & SELECT) {
600 col[0] = col[1] = col[2] = 255;
602 else if ((((int)background_col[0] + (int)background_col[1] + (int)background_col[2]) / 3) < 50) {
603 col[0] = col[1] = col[2] = 80; /* use lighter text color for dark background */
606 col[0] = col[1] = col[2] = 0;
614 UI_view2d_text_cache_rectf(v2d, &rect, str, col);
617 /* draws a shaded strip, made from gradient + flat color + gradient */
618 static void draw_shadedstrip(Sequence *seq, unsigned char col[3], float x1, float y1, float x2, float y2)
622 if (seq->flag & SEQ_MUTE) {
623 glEnable(GL_POLYGON_STIPPLE);
624 glPolygonStipple(stipple_halftone);
627 ymid1 = (y2 - y1) * 0.25f + y1;
628 ymid2 = (y2 - y1) * 0.65f + y1;
630 glShadeModel(GL_SMOOTH);
633 if (seq->flag & SEQ_INVALID_EFFECT) { col[0] = 255; col[1] = 0; col[2] = 255; }
634 else if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, -50);
635 /* else UI_GetColorPtrShade3ubv(col, col, 0); */ /* DO NOTHING */
642 if (seq->flag & SEQ_INVALID_EFFECT) { col[0] = 255; col[1] = 0; col[2] = 255; }
643 else if (seq->flag & SELECT) UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, 5);
644 else UI_GetColorPtrShade3ubv(col, col, -5);
646 glColor3ubv((GLubyte *)col);
648 glVertex2f(x2, ymid1);
649 glVertex2f(x1, ymid1);
653 glRectf(x1, ymid1, x2, ymid2);
657 glVertex2f(x1, ymid2);
658 glVertex2f(x2, ymid2);
660 if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, -15);
661 else UI_GetColorPtrShade3ubv(col, col, 25);
663 glColor3ubv((GLubyte *)col);
670 if (seq->flag & SEQ_MUTE) {
671 glDisable(GL_POLYGON_STIPPLE);
676 * Draw a sequence strip, bounds check already made
677 * ARegion is currently only used to get the windows width in pixels
678 * so wave file sample drawing precision is zoom adjusted
680 static void draw_seq_strip(Scene *scene, ARegion *ar, Sequence *seq, int outline_tint, float pixelx)
682 View2D *v2d = &ar->v2d;
683 float x1, x2, y1, y2;
684 unsigned char col[3], background_col[3], is_single_image;
685 const float handsize_clamped = draw_seq_handle_size_get_clamped(seq, pixelx);
687 /* we need to know if this is a single image/color or not for drawing */
688 is_single_image = (char)BKE_sequence_single_check(seq);
691 x1 = (seq->startstill) ? seq->start : seq->startdisp;
692 y1 = seq->machine + SEQ_STRIP_OFSBOTTOM;
693 x2 = (seq->endstill) ? (seq->start + seq->len) : seq->enddisp;
694 y2 = seq->machine + SEQ_STRIP_OFSTOP;
697 /* get the correct color per strip type*/
698 //get_seq_color3ubv(scene, seq, col);
699 get_seq_color3ubv(scene, seq, background_col);
701 /* draw the main strip body */
702 if (is_single_image) { /* single image */
703 draw_shadedstrip(seq, background_col,
704 BKE_sequence_tx_get_final_left(seq, 0), y1,
705 BKE_sequence_tx_get_final_right(seq, 0), y2);
707 else { /* normal operation */
708 draw_shadedstrip(seq, background_col, x1, y1, x2, y2);
711 /* draw additional info and controls */
712 if (!is_single_image)
713 draw_seq_extensions(scene, ar, seq);
715 draw_seq_handle(v2d, seq, handsize_clamped, SEQ_LEFTHANDLE);
716 draw_seq_handle(v2d, seq, handsize_clamped, SEQ_RIGHTHANDLE);
718 /* draw the strip outline */
722 /* draw sound wave */
723 if (seq->type == SEQ_TYPE_SOUND_RAM) {
724 drawseqwave(scene, seq, x1, y1, x2, y2, BLI_RCT_SIZE_X(&ar->v2d.cur) / ar->winx);
728 if (seq->flag & SEQ_LOCK) {
729 glEnable(GL_POLYGON_STIPPLE);
733 glColor4ub(255, 255, 255, 32);
734 glPolygonStipple(stipple_diag_stripes_pos);
735 glRectf(x1, y1, x2, y2);
738 glColor4ub(0, 0, 0, 32);
739 glPolygonStipple(stipple_diag_stripes_neg);
740 glRectf(x1, y1, x2, y2);
742 glDisable(GL_POLYGON_STIPPLE);
746 if (!BKE_seqence_is_valid_check(seq)) {
747 glEnable(GL_POLYGON_STIPPLE);
750 glColor4ub(255, 0, 0, 255);
751 glPolygonStipple(stipple_diag_stripes_pos);
752 glRectf(x1, y1, x2, y2);
754 glDisable(GL_POLYGON_STIPPLE);
757 get_seq_color3ubv(scene, seq, col);
758 if (G.moving && (seq->flag & SELECT)) {
759 if (seq->flag & SEQ_OVERLAP) {
760 col[0] = 255; col[1] = col[2] = 40;
763 UI_GetColorPtrShade3ubv(col, col, 120 + outline_tint);
766 UI_GetColorPtrShade3ubv(col, col, outline_tint);
768 glColor3ubv((GLubyte *)col);
770 if (seq->flag & SEQ_MUTE) {
771 glEnable(GL_LINE_STIPPLE);
772 glLineStipple(1, 0x8888);
775 uiDrawBoxShade(GL_LINE_LOOP, x1, y1, x2, y2, 0.0, 0.1, 0.0);
777 if (seq->flag & SEQ_MUTE) {
778 glDisable(GL_LINE_STIPPLE);
781 if (seq->type == SEQ_TYPE_META) {
782 drawmeta_contents(scene, seq, x1, y1, x2, y2);
785 /* calculate if seq is long enough to print a name */
786 x1 = seq->startdisp + handsize_clamped;
787 x2 = seq->enddisp - handsize_clamped;
789 /* info text on the strip */
790 if (x1 < v2d->cur.xmin) x1 = v2d->cur.xmin;
791 else if (x1 > v2d->cur.xmax) x1 = v2d->cur.xmax;
792 if (x2 < v2d->cur.xmin) x2 = v2d->cur.xmin;
793 else if (x2 > v2d->cur.xmax) x2 = v2d->cur.xmax;
795 /* nice text here would require changing the view matrix for texture text */
796 if ((x2 - x1) / pixelx > 32) {
797 draw_seq_text(v2d, seq, x1, x2, y1, y2, background_col);
801 static Sequence *special_seq_update = NULL;
803 static void UNUSED_FUNCTION(set_special_seq_update) (int val)
807 /* if mouse over a sequence && LEFTMOUSE */
809 // XXX special_seq_update= find_nearest_seq(&x);
811 else special_seq_update = NULL;
814 ImBuf *sequencer_ibuf_get(struct Main *bmain, Scene *scene, SpaceSeq *sseq, int cfra, int frame_ofs)
816 SeqRenderData context;
819 float render_size = 0.0;
820 float proxy_size = 100.0;
822 render_size = sseq->render_size;
823 if (render_size == 0) {
824 render_size = scene->r.size;
827 proxy_size = render_size;
830 if (render_size < 0) {
834 rectx = (render_size * (float)scene->r.xsch) / 100.0f + 0.5f;
835 recty = (render_size * (float)scene->r.ysch) / 100.0f + 0.5f;
837 context = BKE_sequencer_new_render_data(bmain, scene, rectx, recty, proxy_size);
839 if (special_seq_update)
840 ibuf = BKE_sequencer_give_ibuf_direct(context, cfra + frame_ofs, special_seq_update);
841 else if (!U.prefetchframes) // XXX || (G.f & G_PLAYANIM) == 0) {
842 ibuf = BKE_sequencer_give_ibuf(context, cfra + frame_ofs, sseq->chanshown);
844 ibuf = BKE_sequencer_give_ibuf_threaded(context, cfra + frame_ofs, sseq->chanshown);
849 void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq, int cfra, int frame_ofs, int draw_overlay)
851 struct Main *bmain = CTX_data_main(C);
852 struct ImBuf *ibuf = NULL;
853 struct ImBuf *scope = NULL;
854 struct View2D *v2d = &ar->v2d;
855 /* int rectx, recty; */ /* UNUSED */
856 float viewrectx, viewrecty;
857 float render_size = 0.0;
858 float proxy_size = 100.0;
863 render_size = sseq->render_size;
864 if (render_size == 0) {
865 render_size = scene->r.size;
868 proxy_size = render_size;
870 if (render_size < 0) {
874 viewrectx = (render_size * (float)scene->r.xsch) / 100.0f;
875 viewrecty = (render_size * (float)scene->r.ysch) / 100.0f;
877 /* rectx = viewrectx + 0.5f; */ /* UNUSED */
878 /* recty = viewrecty + 0.5f; */ /* UNUSED */
880 if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
881 viewrectx *= scene->r.xasp / scene->r.yasp;
882 viewrectx /= proxy_size / 100.0f;
883 viewrecty /= proxy_size / 100.0f;
886 if (!draw_overlay || sseq->overlay_type == SEQ_DRAW_OVERLAY_REFERENCE) {
887 UI_GetThemeColor3fv(TH_SEQ_PREVIEW, col);
888 glClearColor(col[0], col[1], col[2], 0.0);
889 glClear(GL_COLOR_BUFFER_BIT);
892 /* without this colors can flicker from previous opengl state */
893 glColor4ub(255, 255, 255, 255);
895 UI_view2d_totRect_set(v2d, viewrectx + 0.5f, viewrecty + 0.5f);
896 UI_view2d_curRect_validate(v2d);
898 /* only initialize the preview if a render is in progress */
902 ibuf = sequencer_ibuf_get(bmain, scene, sseq, cfra, frame_ofs);
907 if (ibuf->rect == NULL && ibuf->rect_float == NULL)
910 switch (sseq->mainb) {
911 case SEQ_DRAW_IMG_IMBUF:
912 if (sseq->zebra != 0) {
913 scope = make_zebra_view_from_ibuf(ibuf, sseq->zebra);
916 case SEQ_DRAW_IMG_WAVEFORM:
917 if ((sseq->flag & SEQ_DRAW_COLOR_SEPARATED) != 0) {
918 scope = make_sep_waveform_view_from_ibuf(ibuf);
921 scope = make_waveform_view_from_ibuf(ibuf);
924 case SEQ_DRAW_IMG_VECTORSCOPE:
925 scope = make_vectorscope_view_from_ibuf(ibuf);
927 case SEQ_DRAW_IMG_HISTOGRAM:
928 scope = make_histogram_view_from_ibuf(ibuf);
937 if (ibuf->rect_float && ibuf->rect == NULL) {
938 IMB_rect_from_float(ibuf);
941 /* setting up the view - actual drawing starts here */
942 UI_view2d_view_ortho(v2d);
944 last_texid = glaGetOneInteger(GL_TEXTURE_2D);
945 glEnable(GL_TEXTURE_2D);
946 glGenTextures(1, (GLuint *)&texid);
948 glBindTexture(GL_TEXTURE_2D, texid);
950 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
951 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
953 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ibuf->x, ibuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
957 if (sseq->overlay_type == SEQ_DRAW_OVERLAY_RECT) {
959 tot_clip.xmin = v2d->tot.xmin + (ABS(BLI_RCT_SIZE_X(&v2d->tot)) * scene->ed->over_border.xmin);
960 tot_clip.ymin = v2d->tot.ymin + (ABS(BLI_RCT_SIZE_Y(&v2d->tot)) * scene->ed->over_border.ymin);
961 tot_clip.xmax = v2d->tot.xmin + (ABS(BLI_RCT_SIZE_X(&v2d->tot)) * scene->ed->over_border.xmax);
962 tot_clip.ymax = v2d->tot.ymin + (ABS(BLI_RCT_SIZE_Y(&v2d->tot)) * scene->ed->over_border.ymax);
964 glTexCoord2f(scene->ed->over_border.xmin, scene->ed->over_border.ymin); glVertex2f(tot_clip.xmin, tot_clip.ymin);
965 glTexCoord2f(scene->ed->over_border.xmin, scene->ed->over_border.ymax); glVertex2f(tot_clip.xmin, tot_clip.ymax);
966 glTexCoord2f(scene->ed->over_border.xmax, scene->ed->over_border.ymax); glVertex2f(tot_clip.xmax, tot_clip.ymax);
967 glTexCoord2f(scene->ed->over_border.xmax, scene->ed->over_border.ymin); glVertex2f(tot_clip.xmax, tot_clip.ymin);
969 else if (sseq->overlay_type == SEQ_DRAW_OVERLAY_REFERENCE) {
970 glTexCoord2f(0.0f, 0.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymin);
971 glTexCoord2f(0.0f, 1.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymax);
972 glTexCoord2f(1.0f, 1.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymax);
973 glTexCoord2f(1.0f, 0.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymin);
977 glTexCoord2f(0.0f, 0.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymin);
978 glTexCoord2f(0.0f, 1.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymax);
979 glTexCoord2f(1.0f, 1.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymax);
980 glTexCoord2f(1.0f, 0.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymin);
983 glBindTexture(GL_TEXTURE_2D, last_texid);
984 glDisable(GL_TEXTURE_2D);
985 glDeleteTextures(1, &texid);
987 if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
989 float x1 = v2d->tot.xmin;
990 float y1 = v2d->tot.ymin;
991 float x2 = v2d->tot.xmax;
992 float y2 = v2d->tot.ymax;
997 UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 1.0, 0);
999 glBegin(GL_LINE_LOOP);
1000 glVertex2f(x1 - 0.5f, y1 - 0.5f);
1001 glVertex2f(x1 - 0.5f, y2 + 0.5f);
1002 glVertex2f(x2 + 0.5f, y2 + 0.5f);
1003 glVertex2f(x2 + 0.5f, y1 - 0.5f);
1007 if ((sseq->flag & SEQ_DRAW_SAFE_MARGINS) != 0) {
1010 float a = fac * (x2 - x1);
1014 a = fac * (y2 - y1);
1018 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
1020 uiSetRoundBox(UI_CNR_ALL);
1021 uiDrawBox(GL_LINE_LOOP, x1, y1, x2, y2, 12.0);
1023 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1030 /* draw grease-pencil (image aligned) */
1031 draw_gpencil_2dimage(C);
1033 IMB_freeImBuf(ibuf);
1035 /* ortho at pixel level */
1036 UI_view2d_view_restore(C);
1038 /* draw grease-pencil (screen aligned) */
1039 draw_gpencil_view2d(C, 0);
1043 /* NOTE: sequencer mask editing isnt finished, the draw code is working but editing not,
1044 * for now just disable drawing since the strip frame will likely be offset */
1046 //if (sc->mode == SC_MODE_MASKEDIT) {
1047 if (0 && sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
1048 Mask *mask = BKE_sequencer_mask_get(scene);
1052 // ED_mask_get_size(C, &width, &height);
1054 //Scene *scene = CTX_data_scene(C);
1055 width = (scene->r.size * scene->r.xsch) / 100;
1056 height = (scene->r.size * scene->r.ysch) / 100;
1058 ED_mask_draw_region(mask, ar,
1069 void drawprefetchseqspace(Scene *scene, ARegion *UNUSED(ar), SpaceSeq *sseq)
1072 int render_size = sseq->render_size;
1073 int proxy_size = 100.0;
1074 if (render_size == 0) {
1075 render_size = scene->r.size;
1078 proxy_size = render_size;
1080 if (render_size < 0) {
1084 rectx = (render_size * scene->r.xsch) / 100;
1085 recty = (render_size * scene->r.ysch) / 100;
1087 if (sseq->mainb != SEQ_DRAW_SEQUENCE) {
1088 give_ibuf_prefetch_request(
1089 rectx, recty, (scene->r.cfra), sseq->chanshown,
1095 /* draw backdrop of the sequencer strips view */
1096 static void draw_seq_backdrop(View2D *v2d)
1100 /* darker gray overlay over the view backdrop */
1101 UI_ThemeColorShade(TH_BACK, -20);
1102 glRectf(v2d->cur.xmin, -1.0, v2d->cur.xmax, 1.0);
1104 /* Alternating horizontal stripes */
1105 i = maxi(1, ((int)v2d->cur.ymin) - 1);
1108 while (i < v2d->cur.ymax) {
1110 UI_ThemeColorShade(TH_BACK, -15);
1112 UI_ThemeColorShade(TH_BACK, -25);
1114 glVertex2f(v2d->cur.xmax, i);
1115 glVertex2f(v2d->cur.xmin, i);
1116 glVertex2f(v2d->cur.xmin, i + 1);
1117 glVertex2f(v2d->cur.xmax, i + 1);
1123 /* Darker lines separating the horizontal bands */
1124 i = maxi(1, ((int)v2d->cur.ymin) - 1);
1125 UI_ThemeColor(TH_GRID);
1128 while (i < v2d->cur.ymax) {
1129 glVertex2f(v2d->cur.xmax, i);
1130 glVertex2f(v2d->cur.xmin, i);
1137 /* draw the contents of the sequencer strips view */
1138 static void draw_seq_strips(const bContext *C, Editing *ed, ARegion *ar)
1140 Scene *scene = CTX_data_scene(C);
1141 View2D *v2d = &ar->v2d;
1142 Sequence *last_seq = BKE_sequencer_active_get(scene);
1144 float pixelx = BLI_RCT_SIZE_X(&v2d->cur) / BLI_RCT_SIZE_X(&v2d->mask);
1146 /* loop through twice, first unselected, then selected */
1147 for (j = 0; j < 2; j++) {
1149 int outline_tint = (j) ? -60 : -150; /* highlighting around strip edges indicating selection */
1151 /* loop through strips, checking for those that are visible */
1152 for (seq = ed->seqbasep->first; seq; seq = seq->next) {
1153 /* boundbox and selection tests for NOT drawing the strip... */
1154 if ((seq->flag & SELECT) != sel) continue;
1155 else if (seq == last_seq) continue;
1156 else if (MIN2(seq->startdisp, seq->start) > v2d->cur.xmax) continue;
1157 else if (MAX2(seq->enddisp, seq->start + seq->len) < v2d->cur.xmin) continue;
1158 else if (seq->machine + 1.0f < v2d->cur.ymin) continue;
1159 else if (seq->machine > v2d->cur.ymax) continue;
1161 /* strip passed all tests unscathed... so draw it now */
1162 draw_seq_strip(scene, ar, seq, outline_tint, pixelx);
1165 /* draw selected next time round */
1169 /* draw the last selected last (i.e. 'active' in other parts of Blender), removes some overlapping error */
1171 draw_seq_strip(scene, ar, last_seq, 120, pixelx);
1174 static void seq_draw_sfra_efra(Scene *scene, View2D *v2d)
1178 /* draw darkened area outside of active timeline
1179 * frame range used is preview range or scene range */
1180 UI_ThemeColorShadeAlpha(TH_BACK, -25, -100);
1182 if (PSFRA < PEFRA) {
1183 glRectf(v2d->cur.xmin, v2d->cur.ymin, (float)PSFRA, v2d->cur.ymax);
1184 glRectf((float)PEFRA, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
1187 glRectf(v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
1190 UI_ThemeColorShade(TH_BACK, -60);
1191 /* thin lines where the actual frames are */
1192 fdrawline((float)PSFRA, v2d->cur.ymin, (float)PSFRA, v2d->cur.ymax);
1193 fdrawline((float)PEFRA, v2d->cur.ymin, (float)PEFRA, v2d->cur.ymax);
1195 glDisable(GL_BLEND);
1198 /* Draw Timeline/Strip Editor Mode for Sequencer */
1199 void draw_timeline_seq(const bContext *C, ARegion *ar)
1201 Scene *scene = CTX_data_scene(C);
1202 Editing *ed = BKE_sequencer_editing_get(scene, FALSE);
1203 SpaceSeq *sseq = CTX_wm_space_seq(C);
1204 View2D *v2d = &ar->v2d;
1205 View2DScrollers *scrollers;
1206 short unit = 0, flag = 0;
1209 /* clear and setup matrix */
1210 UI_GetThemeColor3fv(TH_BACK, col);
1211 if (ed && ed->metastack.first)
1212 glClearColor(col[0], col[1], col[2] - 0.1f, 0.0f);
1214 glClearColor(col[0], col[1], col[2], 0.0f);
1215 glClear(GL_COLOR_BUFFER_BIT);
1217 UI_view2d_view_ortho(v2d);
1220 /* calculate extents of sequencer strips/data
1221 * NOTE: needed for the scrollers later
1223 boundbox_seq(scene, &v2d->tot);
1227 draw_seq_backdrop(v2d);
1229 /* regular grid-pattern over the rest of the view (i.e. 25-frame grid lines) */
1230 // NOTE: the gridlines are currently spaced every 25 frames, which is only fine for 25 fps, but maybe not for 30...
1231 UI_view2d_constant_grid_draw(v2d);
1233 seq_draw_sfra_efra(scene, v2d);
1235 /* sequence strips (if there is data available to be drawn) */
1238 draw_seq_strips(C, ed, ar);
1240 /* text draw cached (for sequence names), in pixelspace now */
1241 UI_view2d_text_cache_draw(ar);
1245 UI_view2d_view_ortho(v2d);
1246 if ((sseq->flag & SEQ_DRAWFRAMES) == 0) flag |= DRAWCFRA_UNIT_SECONDS;
1247 if ((sseq->flag & SEQ_NO_DRAW_CFRANUM) == 0) flag |= DRAWCFRA_SHOW_NUMBOX;
1248 ANIM_draw_cfra(C, v2d, flag);
1251 UI_view2d_view_orthoSpecial(ar, v2d, 1);
1252 draw_markers_time(C, DRAW_MARKERS_LINES);
1255 UI_view2d_view_ortho(v2d);
1256 ANIM_draw_previewrange(C, v2d);
1258 /* overlap playhead */
1259 if (scene->ed && scene->ed->over_flag & SEQ_EDIT_OVERLAY_SHOW) {
1260 int cfra_over = (scene->ed->over_flag & SEQ_EDIT_OVERLAY_ABS) ? scene->ed->over_cfra : scene->r.cfra + scene->ed->over_ofs;
1261 glColor3f(0.2, 0.2, 0.2);
1262 // glRectf(cfra_over, v2d->cur.ymin, scene->ed->over_ofs + scene->r.cfra + 1, v2d->cur.ymax);
1265 glVertex2f(cfra_over, v2d->cur.ymin);
1266 glVertex2f(cfra_over, v2d->cur.ymax);
1271 /* reset view matrix */
1272 UI_view2d_view_restore(C);
1275 unit = (sseq->flag & SEQ_DRAWFRAMES) ? V2D_UNIT_FRAMES : V2D_UNIT_SECONDSSEQ;
1276 scrollers = UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_UNIT_VALUES, V2D_GRID_CLAMP);
1277 UI_view2d_scrollers_draw(C, v2d, scrollers);
1278 UI_view2d_scrollers_free(scrollers);